c# - System.NotSupportedException:The entity or complex type Model.APPLICANT cannot be constructed in a LINQ to Entities query -


currently fixing codes until exception occured

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

this controller :

public ienumerable<applicant> getapplicant() {     ienumerable<applicant> applicantdata = cache.get("applicants") ienumerable<applicant>;       if (applicantdata == null)     {          var applicantlist = (from app in context.applicants                              join in context.profiles                              on app.profile_id equals a.profile_id output                              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;  } 

the exception appears @ line

if (applicantdata.any())

i hope can suggest or can find way solve problem . . thanks

since can't create new instances of non-ef type in query can split query 2 parts.

first data

var data = app in context.applicants            join in context.profiles              on app.profile_id equals a.profile_id output            j in output.defaultifempty()            select new {               id = app.applicant_id,               lastname =                 (j == null ? app.applicant_lastname : j.applicant_lastname)             };  var applicantdata = data.take(1000)   .where(v => !string.isnullorempty(v.applicant_lastname)); 

then initialize instances

var applicants = (from in applicantdata                   select new applicant() {                      applicant_id = a.id,                      applicant_lastname = a.lastname                   }                  ).asenumerable(); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -