0

I have a class defined as follows:

public class SearchResult
{
    public Customer Customer { get; set; }
    public Receipt Receipt { get; set; }
    public IEnumerable<ReceiptDetail> ReceiptDetail { get; set; }
}

In my Linq query i would like to return a single SearchResult record but have problems in returning the List of ReceiptDetail. If i do:

 var list=(from cust in dbContext.Customers 
     join rec in dbContext.Receipts on cust.IdCustomer equals rec.IdCustomer
     join recdet in dbContext.ReceiptDetails on rec.IdReceipt equals recdet.IdReceipt
     select new SearchResult
     {
          Customer=cust,
          Receipt=rec,
          ReceiptDetail = (from  r1 in recdet select r1).ToList() // COMPILER ERROR HERE
     }).ToList();

I get the "Could not find an implementation of the query pattern for source type ReceiptDetail 'Select' not found".

What am i doing wrong?

1 Answer 1

1

Well, recdet comes from here:

join recdet in dbContext.ReceiptDetails on rec.IdReceipt equals recdet.IdReceipt

That means it's a single receipt detail. You're then trying to use it as a collection here:

from  r1 in recdet select r1

I suspect you actually want a group join:

join recdet in dbContext.ReceiptDetails on rec.IdReceipt equals recdet.IdReceipt
  into recdets
...
ReceiptDetail = (from  r1 in recdets select r1).ToList()

or more simply for the latter part:

ReceiptDetail = recdets.ToList()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.