【问题标题】:The entity or complex type '' cannot be constructed in a LINQ to Entities query无法在 LINQ to Entities 查询中构造实体或复杂类型“”
【发布时间】:2015-05-19 18:41:24
【问题描述】:

我正在尝试在两个表之间进行左连接并在运行时出现以下错误

错误消息 - 无法在 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();

【问题讨论】:

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


    【解决方案1】:

    下面的代码解决了这个问题。无需将右侧表作为类传递

    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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-11
      • 2017-05-31
      • 2015-02-06
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多