c# - The Entity or complex type cannot be constructed in a Linq to Entity Query -


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

system.notsupportedexception: entity or complex type 'model.applicant' cannot constructed in linq entities query.

select new applicant() 

entity framework not support this. gets diagnosed when query used, not when query constructed, why line exception confusing.

you can construct type isn't database entity, including anonymous types, can do

select new {     a.applicant_lastname,     a.applicant_firstname,     a.applicant_middlename,     a.applicant_address,     a.applicant_city,     a.applicant_phone,     a.applicant_email } 

and can, if required, put values applicant objects after query has finished executing.

or, if appropriate, can applicant directly:

select app 

i'm not sure why have applicant_lastname etc. in both profile , applicant, , not know if values same. if not, last suggestion won't of use you.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -