简体   繁体   English

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

[英]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.

相关问题 实体或复杂类型&#39;x&#39;不能在linq to实体查询中构造 - the entity or complex type 'x' cannot be constructed in a linq to entities query 实体或 &gt; 复杂类型“ChildAccessory”不能在 LINQ 中构造到 &gt; 实体查询 - The entity or > complex type 'ChildAccessory' cannot be constructed in a LINQ to > Entities query 无法在 LINQ to Entities 查询中构造实体或复杂类型“ ” - The entity or complex type ' ' cannot be constructed in a LINQ to Entities query C#-无法在LINQ to Entities查询中构造实体或复杂类型 - C# - The entity or complex type cannot be constructed in a LINQ to Entities query 实体或复杂类型……无法在LINQ to Entities查询中构造 - The entity or complex type … cannot be constructed in a LINQ to Entities query 收到错误:无法在LINQ to Entities查询中构造实体或复杂类型 - Getting error:The entity or complex type cannot be constructed in a LINQ to Entities query 实体或复杂类型不能在LINQ to Entities查询中构造 - The entity or complex type cannot be constructed in a LINQ to Entities query “Controler中的实体或复杂类型不能在LINQ to Entities查询中构造” - “The entity or complex type cannot be constructed in a LINQ to Entities query” in Controler 实体或复杂类型“ xxx”不能在LINQ to Entities查询中构造吗? - The entity or complex type 'xxx' cannot be constructed in a LINQ to Entities query? 无法在LINQ to Entities查询中构造实体或复杂类型&#39;xyz&#39; - The entity or complex type 'xyz' cannot be constructed in a LINQ to Entities query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM