c# 3.0 - Error: The entity or complex type cannot be constructed in a LINQ to Entities query ASP.NET MVC3 -
good day all.
im having entity or complex type cannot encountered first time encountered type of error me
public ienumerable<applicant> getapplicant() { ienumerable<applicant> applicantdata = cache.get("applicants") ienumerable<applicant>; ienumerable<profile> profiledata = cache.get("profiles") ienumerable<profile>; if (applicantdata == null) { var applicantlist = (from in context.profiles join app in context.applicants on a.profile_id equals app.profile_id app.applicant_logicaldelete == false select new applicant() { applicant_lastname = a.applicant_lastname, applicant_firstname = a.applicant_firstname, applicant_middlename = a.applicant_middlename, applicant_address = a.applicant_address, applicant_city = a.applicant_city, applicant_phone = a.applicant_phone, applicant_email= a.applicant_email }); applicantdata = applicantlist.where(v => !string.isnullorempty(v.applicant_lastname)).orderby(v => v.applicant_id).tolist(); if (applicantdata.any()) { cache.set("applicants", applicantdata, 30); } } return applicantdata.tolist().take(1000); }
and line encounter error thanks!
applicantdata = applicantlist.where(v => !string.isnullorempty(v.applicant_lastname)).orderby(v => v.applicant_id).tolist();
and error in line above is
system.notsupportedexception: entity or complex type 'model.applicant' cannot constructed in linq entities query.
it looks me query constructing objects of type registerd entity type. don't need initalize such objects select new{...}.
try change query this:
var applicantlist = (from in context.profiles join app in context.applicants on a.profile_id equals app.profile_id app.applicant_logicaldelete == false select app ); ..........
Comments
Post a Comment