实体或复杂类型''不能在LINQ to Entities查询中构造 [英] The entity or complex type '' cannot be constructed in a LINQ to Entities query

查看:81
本文介绍了实体或复杂类型''不能在LINQ to Entities查询中构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to do left join between two tables and getting following error at runtime

错误消息-实体或复杂类型'XactETLModel.XactETL_ShredQueue_Exceptions'不能在LINQ to Entities查询中构造.

Error Message - The entity or complex type 'XactETLModel.XactETL_ShredQueue_Exceptions' cannot be constructed in a LINQ to Entities query.

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

推荐答案

以下代码解决了该问题.无需将右侧表作为类传递

Following code fix the issue. No need to pass the right side table as class

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

这篇关于实体或复杂类型''不能在LINQ to Entities查询中构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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