locked
Projecting onto nested List RRS feed

  • Question

  • I'm trying to project into a list of Customer, however the customer has a list of Invoices. I am having trouble inserting into the list from my IQueryable I know the IQueryable has the Child Invoices as I have cast it to a list I just can't map to my object.

    (from c in _baseQuery
                                 select new Customer
                                            {
                                                CustomerId = c.CustomerID, FirstName = c.FirstName,LastName = c.LastName
                                                ,
                                                Invoices = (from d in (from d in _baseQuery select d.Invoices)
                                                                 select new Invoice() {InvDesc = d.First().InvDesc}).ToList()
                                            }).AsQueryable();


    Chris
    Sunday, October 30, 2011 6:52 PM

Answers

  • Hi Chris;

    From your query I believe that you are looking for is the following snippet. I am assuming that the c variable in your query from the _baseQuery has a One to Many relationship to the Invoices.

    (from c in _baseQuery
     select new Customer
     {
         CustomerId = c.CustomerID, 
         FirstName = c.FirstName,
         LastName = c.LastName,
         Invoices = (from d in c.Invoices
                     select new Invoice() 
                     {
                         InvDesc = d.InvDesc
                     }).ToList()
     }).AsQueryable();
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Alan_chen Monday, October 31, 2011 3:21 AM
    • Marked as answer by Alan_chen Tuesday, November 8, 2011 6:52 AM
    Sunday, October 30, 2011 8:14 PM

All replies

  • Hi Chris;

    From your query I believe that you are looking for is the following snippet. I am assuming that the c variable in your query from the _baseQuery has a One to Many relationship to the Invoices.

    (from c in _baseQuery
     select new Customer
     {
         CustomerId = c.CustomerID, 
         FirstName = c.FirstName,
         LastName = c.LastName,
         Invoices = (from d in c.Invoices
                     select new Invoice() 
                     {
                         InvDesc = d.InvDesc
                     }).ToList()
     }).AsQueryable();
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Alan_chen Monday, October 31, 2011 3:21 AM
    • Marked as answer by Alan_chen Tuesday, November 8, 2011 6:52 AM
    Sunday, October 30, 2011 8:14 PM
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, November 4, 2011 6:36 AM