左外连接在实体数据模型asp.net [英] Left Outer Join in Entity Data Model asp.net

查看:191
本文介绍了左外连接在实体数据模型asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现左外Linq中加入到实体框架。不支持DefaultIfEmpty功能。
请提供一个例子。

how to implement Left outer join in Linq to entity framework. DefaultIfEmpty function is not supported. please provide an example.

推荐答案

这工作在.NET 3.5。当你加入无,从做与FirstorDefault功能组合,它会给你你正在寻找左连接表的行。如果你想多行,只需使用其中(),而不是..希望这会有所帮助。

This works in .NET 3.5. When you join without doing "from" in combination with the FirstorDefault function, it will give you the row you are looking for in the left joined table. If you want multiple rows, just use where() instead.. Hope this helps.

====

comments = from p in _db.Master

join t in _db.Details on p.DetailID equals t.DetailID into tg

select new 
{

 A = p.Column1,

//this next column is the one from the left joined table

 B = tg.FirstOrDefault(t => t.DetailID == p.DetailID).Column2

};

这篇关于左外连接在实体数据模型asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆