我在使用linq进行左/右连接时遇到问题。sql左linq lampda表达式加入
我可以说
public class Customer
{
prop string CustomerId { get; set; }
prop string LanguageGuid { get; set; }
}
public class ReadOnlyCustomer
{
prop string CustomerId { get; set; }
prop string LanguageGuid { get; set; }
}
我在ReadonlyCustomer表中的很多客户。 在我的情况下,我没有客户表中的所有客户。 所以我不能使用加入,我不是什么内部加入。 我需要左或右连接。
var test = db.Customer.Join(db.ReadOnlyCustomer, p => p.CustomerId, o => o.CustomerId, (c, o) => new ReadOnlyCustomer() { CustomerId = c.CustomerId, LanguageGuid = o.LanguageGuid ?? c.LanguageGuid });
在这一点上,我得到一个空指针,因为查询不能加入一个空引用。
我该如何做一个左连接等于sql左连接,其中我得到的数据源中不存在NULL值为NULL。
这需要在lampda不comprehensing类似语法(邻中....)
//丹尼斯
为什么要求它不能在'comprehensing'语法中?我所知道的唯一简单的解决方案只适用于'理解'语法:http://codingsense.wordpress.com/2009/03/08/left-join-right-join-using-linq/ – mellamokb