我有一个定义如下的类:
public class SearchResult
{
public Customer Customer { get; set; }
public Receipt Receipt { get; set; }
public IEnumerable<ReceiptDetail> ReceiptDetail { get; set; }
}
在我的 Linq 查询中,我想返回单个 SearchResult 记录,但在返回 ReceiptDetail 列表时遇到问题。如果我做:
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();
我得到“找不到源类型 ReceiptDetail 'Select' 的查询模式的实现”。
我究竟做错了什么?