开发者

left join using lambda expression

I have tableA and tableB.

I would like 开发者_StackOverflowto perform left join using lambda expression. This is the equal sql statement:

SELECT *
FROM tableA A
    LEFT JOIN tableB B ON A.userId=B.userId

How can I do that using lambda expression?


It's usually an error to use an explicit join in LINQ to Entities.

Instead, use the navigation properties:

var q = Context.TableAs.Select(a => new { a.Foo, a.TableB.Bar });

LINQ to Entities will coalesce null references. So if a.TableB is null for some record in TableAs, then a.TableB.Bar will return null instead of giving you a null reference exception. So it behaves like a SQL LEFT JOIN

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜