首页 > 代码库 > Linq join on 多条件
Linq join on 多条件
var a = from m in DbContext.Set<T1>() join q in DbContext.Set<T2>() on new { m.ID, Phone=m.Phone1 } equals new { q.ID, Phone=q.Phone2 } where m.Phone1 !=null select new { m.ID, m.Phone1 }; a = a.OrderBy(m => m.Phone1).Skip(2).Take(2);
SELECT [Extent1].[ID] AS [ID], [Extent1].[Phone1] AS [Phone1], 1 AS [C1] FROM [dbo].[T1] AS [Extent1] INNER JOIN [dbo].[T2] AS [Extent2] ON ([Extent1].[ID] = [Extent2].[ID]) AND (([Extent1].[Phone1] = [Extent2].[Phone2]) OR (([Extent1].[Phone1] IS NULL) AND ([Extent2].[Phone2] IS NULL))) WHERE [Extent1].[Phone1] IS NOT NULL
所以linq为什么要这么写,看到生成的sql语句 就不言而喻了,因为linq多管闲事的将NULL给总结进去了
Linq join on 多条件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。