目前固定我的代碼直到出現異常System.NotSupportedException:實體或複雜類型Model.APPLICANT不能在LINQ構建以查詢實體
System.NotSupportedException: The entity or complex type Model.APPLICANT' cannot be constructed in a LINQ to Entities query
這是我的控制器:
public IEnumerable<APPLICANT> GetApplicant()
{
IEnumerable<APPLICANT> applicantdata = Cache.Get("applicants") as IEnumerable<APPLICANT>;
if (applicantdata == null)
{
var applicantList = (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 APPLICANT() { APPLICANT_ID = app.APPLICANT_ID, APPLICANT_LastName = (j == null ? app.APPLICANT_LastName : j.Applicant_LASTNAME) }).Take(1000).AsEnumerable().AsQueryable();
applicantdata = applicantList.Where(v => !String.IsNullOrEmpty(v.APPLICANT_LastName)).AsEnumerable();
if (applicantdata.Any())
{
Cache.Set("applicants", applicantdata, 30);
}
}
return applicantdata;
}
唯一的例外出現在該行
if (applicantdata.Any())
我希望有人可以建議或可以找到一種方法來解決這個問題。 。謝謝
的可能的複製[實體或複雜類型...不能在LINQ被構造爲實體查詢]( http://stackoverflow.com/questions/28985083/the-entity-or-complex-type-cannot-be-constructed-in-a-linq-to-entities-query) – Sparrow