LINQ:具有多个条件的左外连接
我有两个 IEnumerables,称为 BaseReportDefinitions 和 InputReportDefinitions。我需要做一个左外连接,我想要所有的 InputReportDefinitions 和匹配的 BaseReportDefinitions。两个 IEnumberable 都包含 ReportDefinition 对象,该对象包含需要用作连接键的 ParentName 和 ReportName 属性。我想为匿名对象中的每个(在 BaseReportDefinition 条目的情况下它可能为空)返回 ReportDefinition 对象。
我见过许多 linq 外连接和具有静态第二个条件的外连接的示例,这些外连接经常被放入 where 条件中,但没有真正完全使用两个条件进行连接。
I have two IEnumerables called BaseReportDefinitions and InputReportDefinitions. I need to do a left outer join where i want all the InputReportDefinitions and whichever BaseReportDefinitions that match. Both IEnumberables contain ReportDefinition objects that contain ParentName and ReportName properties that need to be used as the join key. I want to return the ReportDefinition object for each (in the case of BaseReportDefinition entry it may be null) in an anonymous object.
I have seen many examples of linq outer joins and outer joins with a static second condition that often gets put into a where condition but nothing that really uses two conditions fully for the join.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这最终会成为左外连接。我不知道如何将这个怪物转换为查询语句。我认为如果您在末尾添加
AsQueryable()
,它可以在 Linq-to-SQL 中使用,但说实话,我对此没什么经验。编辑:我想通了。更容易阅读:
I believe this ends up being a left outer join. I don't know how to convert this monstrosity to a query statement. I think if you add
AsQueryable()
to the end it could be used in Linq-to-SQL, but honestly, I have little experience with that.EDIT: I figured it out. Much easier to read: