使用 Linq 返回记录列表

发布于 2024-10-21 20:23:02 字数 358 浏览 1 评论 0原文

我有一个 ListCustomer,客户的字段为:Id、FirstName、LastName

我有一个 ListRecords,记录的字段为:CustomerId , RecordId

我有一个 List;记录,记录具有以下字段:Id、FieldA、FieldB

我想取回取决于 List 的所有记录,表示客户存在的所有记录在客户列表中

您有什么想法吗?

谢谢,

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 you have an idea ?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看透却不说透 2024-10-28 20:23:02

我认为这种加入会起作用:

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 或类似的

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

未蓝澄海的烟 2024-10-28 20:23:02

一个简单的方法是使用连接?

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文