[英]The entity or complex type ' ' not be constructed in a LINQ to Entities query
I hope someone can help me because when i edit my code . 我希望有人可以帮助我,因为当我编辑代码时。 an exception shows 异常显示
THIS IS MY CONTROLLER 这是我的控制者
public IEnumerable<APPLICANT> GetApplicant()
{
IEnumerable<APPLICANT> applicantdata = Cache.Get("applicants") as IEnumerable<APPLICANT>;
if (applicantdata == null)
{
var data = from app in context.APPLICANTs
join a in context.Profiles
on app.Profile_id equals a.PROFILE_ID into output
from j in output.DefaultIfEmpty()
select new {
Id = app.APPLICANT_ID,
LastName =
(j == null ? app.APPLICANT_LastName : j.Applicant_LASTNAME)
};
var applicant = data
.Where(v => !String.IsNullOrEmpty(v.LastName))
.Take(1000);
applicantdata = (from a in applicant
select new APPLICANT() {
APPLICANT_ID = a.Id,
APPLICANT_LastName = a.LastName
}).AsEnumerable();
if (applicantdata.Any())
{
Cache.Set("applicants", applicantdata, 30);
}
}
return applicantdata;
}
This is the exception: 这是例外:
NotSupportedException was unhandle by user code. 用户代码未处理NotSupportedException。 The entity or complex type ' ' not be constructed in a LINQ to Entities query. 实体或复杂类型''不能在LINQ to Entities查询中构造。 LINQ ASP.NET LINQ ASP.NET
At this line: 在这一行:
if (applicantdata.Any())
In Linq-to-Entities you can only project to any existing mapped entity type but you can project to an anonymous type 在Linq-to-Entities中,您只能投影到任何现有的映射实体类型,但可以投影到匿名类型
applicantdata = (from a in applicant
select new APPLICANT() {
APPLICANT_ID = a.Id,
APPLICANT_LastName = a.LastName
}).AsEnumerable();
In the above code you are trying to project to 'APPLICANT' type so it will not allow you to do so. 在上面的代码中,您尝试将项目投影为“ APPLICANT”类型,因此将不允许您这样做。 you can try to do it using anonymous type as : 您可以尝试使用匿名类型来做到这一点:
applicantdata = (from a in applicant
select new {
APPLICANT_ID = a.Id,
APPLICANT_LastName = a.LastName
}).AsEnumerable();
Hope this will help! 希望这会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.