【问题标题】:Linq with Left Join using Get list使用获取列表进行左连接的 Linq
【发布时间】:2014-08-07 09:54:18
【问题描述】:

我正在使用带有左连接的 Linq 实体框架。我尝试了很多代码。但是出现错误。我的代码如下。

var ABC = (from p in AgEntities.tbl_PrayerRequest 
           join u in AgEntities.tbl_UserMaster
           on p.User_IndexID equals u.User_IndexID into lj 
           from s in lj.DefaultIfEmpty() 
           select new { p.RequestID, p.RequestName, p.RequestEmail, s.User_LoginID }).ToList();

但我收到以下错误。

错误:

LINQ to Entities 无法识别该方法。

'System.Collections.Generic.IEnumerable1[Solution.Bussines.Entities.tbl_UserMaster] DefaultIfEmpty[tbl_UserMaster](System.Collections.Generic.IEnumerable1[Solution.Bussines.Entities.tbl_UserMaster])' 方法,并且该方法不能翻译成商店表达式

【问题讨论】:

  • 为什么要在可枚举的对象上使用 .DefaultIfEmpty()?

标签: asp.net linq entity-framework c#-4.0 left-join


【解决方案1】:
var ABC = (from p in AgEntities.tbl_PrayerRequest 
           join u in AgEntities.tbl_UserMaster
           on p.User_IndexID equals u.User_IndexID into lj 
           from s in lj.DefaultIfEmpty() 
           select new { p.RequestID, p.RequestName, p.RequestEmail,
                 User_LoginID =s==null?0: s.User_LoginID }).ToList();

【讨论】:

  • 感谢您的宝贵意见..但仍然遇到同样的错误。
  • 请回复我的问题
  • var ABC =(from p in AgEntities.tbl_PrayerRequest.ToList() join u in AgEntities.tbl_UserMaster on p.User_IndexID 等于 u.User_IndexID 到 lj from u in lj.DefaultIfEmpty() select new { p .RequestID, p.RequestName, p.RequestEmail,User_LoginID=(u==null?null:u.User_LoginID)}).ToList();
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 2018-07-11
相关资源
最近更新 更多