开发者

Return a list of record with Linq

I have a List<Customer>Customer, the Customer has as fields : Id, FirstName, LastName

I have a List<Records>Records, the Records has as fields : CustomerId, RecordId

I have a List<Record> Record, the Record has as fields : Id, FieldA, FieldB

I'd like to get back all the the Record depending of the List<Customer> means all the record with the Customer present in the Customer list

Do yo开发者_如何学编程u have an idea ?

Thanks,


I think this join will work:

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

but I also think that the "Records" might be better named CustomerRecordLink or similar


A Simple one would be using joins?

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜