2011-03-11 90 views
0

我有一个List<Customer>Customer,得到了客户的字段:编号,名字,姓氏返回记录列表使用LINQ

我有一个List<Records>Records,该记录已为字段:客户ID,recordId所

我有一个List<Record> Record,记录有作为字段:ID,FIELDA,FieldB

我想拿回全部取决于List<Customer>的记录是指所有存在于客户列表中的客户记录

你有想法吗?

感谢,

回答

3

我觉得这个连接将工作:

from c in Customers 
join r1 in Records on c.Id equals r1.CustomerId 
join r2 in Record on r1.RecordId equals r2.Id 
select r2 

,但我也认为,“记录”会得到更好的命名CustomerRecordLink或类似

0

一个简单的将使用加入?

List<Record> result = 
    (from c in Customer 
    from rs in Records 
    from r in Record 
    where 
    rs.CustomerId == c.id 
    && r.id == rs.RecordId 
    select r).Distinct().ToList();