Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:59:07+00:00 2026-05-16T04:59:07+00:00

I have 2 tables (Document and DocumentClass) that have the following columns: DocumentClass: DocClassID,

  • 0

I have 2 tables (Document and DocumentClass) that have the following columns:

DocumentClass: DocClassID, Name, ParentID

Document: DocID, Name, DocClassID

The DocumentClass table contains parent and child records and the relationship between a parent and a child is the ParentID column. A Document record is linked with a child record in the DocumentClass by the DocClassID foreign key.

Parent records in DocumentClass have ParentID = 0 and Child records in the DocumentClass have ParentID != 0

I want to retrieve a childs Name and that child’s Parents Name from the DocumentClass table.

I Have managed to create a function that does that for me. I send in a list of Document ids, find those DocumentClass records (the child records) that the document is linked to and then find the parent to those child records. Then I put that information I want into a Child class.

public List<Child> GetDocClassInfo(List<int> docIds)
{
var result = from dc in _context.DocClasses
             from d in _context.Documents
             where dc.DocClassID == d.DocClassID
             where dc.DocClassID != 0
             where docIds.Contains(d.DocID)
             select new 
             {
                 children = from p in _context.DocClasses
                            where dc.ParentID == p.DocClassID
                            select new Child
                            {
                                ChildId = dc.DocClassID,
                                ChildDocClassName = dc.DocClassName,
                                ParentId = p.DocClassID,
                                ParentDocClassName = p.DocClassName
                            }
             };

        return result.ToList();
    }

My problem is that I want to have a List to return from the function, but the compiler doesn’t like this at all. I get an error saying that

Cannot implicitly convert type System.Collections.Generic.List``<AnonymousType#1> to System.Collection.Generic.List<Child>.

How can I write that LINQ query to return a List?

Best regards,

OKB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:59:08+00:00Added an answer on May 16, 2026 at 4:59 am
    var result = (from dc in _context.DocClasses
                 join d in _context.Documents
                 on dc.DocClassID equals d.DocClassID
                 where dc.DocClassID != 0 && docIds.Contains(d.DocID)
                 let children = from p in _context.DocClasses
                                where dc.ParentID == p.DocClassID
                                select new Child {
                                                  ChildId = dc.DocClassID,
                                                  ChildDocClassName = dc.DocClassName,
                                                  ParentId = p.DocClassID,
                                                  ParentDocClassName = p.DocClassName
                                                  }
                  select children).SelectMany(c=>c).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: Agents with columns: agentid, name DocumentsRead with columns: agentid, document,
If I have a table structure like this: Transaction [TransID, ...] Document [DocID, TransID,
I have two tables: account_company and document_invoice. Table account_company has 2 columns: company_id and
I have 2 tables, a document table and a content table. They look like
I have a several tables nested within a table that I am parsing using
I have two tables that have already been created. Document and DocumentStyle . They
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have 2 tables : Table document ============================================================================ | id_document | document_address | document_content
I have two tables document (id, file) similarity(id1,id2,similarityvalue) where id1 and id2 are foreign
I have an HTML document where I have two different tables. One is class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.