码迷,mamicode.com
首页 > 其他好文 > 详细

Linq join on 多条件

时间:2016-09-21 18:44:57      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

  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 多条件

标签:

原文地址:http://www.cnblogs.com/njcxwz/p/5893753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!