开发者

left outer join problem

开发者 https://www.devze.com 2022-12-28 12:27 出处:网络
I need to convert some SQL statement to LINQ. How convert L开发者_如何学PythonEFT OUTER JOIN to equivalent LINQ statement?You need to use the DefaultIfEmpty operator. The below code should result in a

I need to convert some SQL statement to LINQ. How convert L开发者_如何学PythonEFT OUTER JOIN to equivalent LINQ statement?


You need to use the DefaultIfEmpty operator. The below code should result in a left outer join.

var q = from c in customers
            join o in orders on c.Key equals o.Key into g
            from o in g.DefaultIfEmpty()
            select new {Name = c.Name, OrderNumber = o == null ? "(no orders)" :     o.OrderNumber};

Credit to: http://www.hookedonlinq.com/OuterJoinSample.ashx

0

精彩评论

暂无评论...
验证码 换一张
取 消