无法在LINQ to Entities查询中构造实体或复杂类型''

时间:2015-05-19 18:41:24

标签: linq entity-framework linq-to-entities

我试图在两个表之间进行左连接并在运行时获得跟随错误

错误消息 - 无法在LINQ to Entities查询中构造实体或复杂类型“XactETLModel.XactETL_ShredQueue_Exceptions”。

var query = (from a in xactCtxt.dctShredCompletes 
                             join b in xactCtxt.XactETL_ShredQueue_Exceptions on a.QueueID equals b.QueueID
                             into c 
                             from d in c.DefaultIfEmpty( new XactETL_ShredQueue_Exceptions() )
                             where a.ShredCompleteDate >= startDate && a.ShredCompleteDate <= endDate
                             select new { a.QueueID , a.ShredMode ,a.ShredCompleteDate , d.ExceptionDate ,d.ErrorMessage }).ToList();

1 个答案:

答案 0 :(得分:0)

以下代码修复了该问题。无需将右侧表作为类

传递
var query = (from a in xactCtxt.dctShredCompletes 
                         join b in xactCtxt.XactETL_ShredQueue_Exceptions on a.QueueID equals b.QueueID
                         into c 
                         from d in c.DefaultIfEmpty(  )
                         where a.ShredCompleteDate >= startDate && a.ShredCompleteDate <= endDate
                         select new { a.QueueID , a.ShredMode ,a.ShredCompleteDate , d.ExceptionDate ,d.ErrorMessage }).ToList();