如何使用两个左连接条件创建linq查询 [英] How to Create linq query with two left join condition
本文介绍了如何使用两个左连接条件创建linq查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个LINQ查询,它有两个左连接条件。
I want to crate a LINQ query which has two left join condition.
For Example:
Select BillMain.ID, BillMain.AccountID, BillMain.ItemID from BillMain Left Join BillSub ON BillMain.Ref = BillSub.Ref AND BillMain.Billing = BillSub.Billing
什么是查询LINQ?
What will be query for LINQ?
推荐答案
试试这个
Try this
var result=from a in BillMain
join b in BillSub on new{a.Ref,a.Billing} equals {b.Ref,b.Billing} into res
from r in res.DefaultIfEmpty()
select new {ID=a.ID,AccountID=a.AccountID,ItemID=a.ItemID};
看看这里: http://smehrozalam.wordpress.com/2010/04/13/linq-how-to-write-queries-with-complex-join-conditions / [ ^ ]。
想法是创建一个匿名对象,两边都有两个字段,并检查它们的相等性。
Have a look here: http://smehrozalam.wordpress.com/2010/04/13/linq-how-to-write-queries-with-complex-join-conditions/[^].
The idea is creating an anonymous object with the two fields on both sides, and checking their equality.
这篇关于如何使用两个左连接条件创建linq查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文