c# - Only primitive types ('such as Int32, String, and Guid') are supported in this context -
i'm getting following error:
unable create constant value of type 'phoenix.intranet.web.clientsettings.componentrole'. primitive types ('such int32, string, , guid') supported in context.
i understand why error occurs. don't understand why code creating error. comparisons against primitive types. comparisons guid guid. error states guids ok.
the error occurs on line (towards bottom):
var vla = (from cir in phoenixentities.componentinroles
code:
list<componentrole> roles; using (imsmembershipentities entities = new imsmembershipentities()) { roles = (from role1 in entities.roles select new componentrole{name = role1.rolename, roleid = role1.roleid} ).tolist(); } list<components> componentinroles; using (phoenixentities phoenixentities = new phoenixentities()) { phoenixentities.contextoptions.lazyloadingenabled = false; componentinroles = (from component in phoenixentities.components select new components{name = component.name, componentid = component.componentid, //inroles = (from componentinrole in phoenixentities.componentinroles // join role in roles on componentinrole.roleid equals role.roleid // componentinrole.componentid == component.componentid // select new componentrole{roleid = role.roleid, name = role.name}) } ).tolist(); foreach (components cmpent in componentinroles) { components cmpent1 = cmpent; //cmpent.inroles = var vla = (from cir in phoenixentities.componentinroles join role in roles on cir.roleid equals role.roleid cir.componentid == cmpent1.componentid select role).tolist(); } }
entityframework , linq sql both try translate such queries part in memory , other part in database, sql in
operator.
and because class roles ienumerable of not primitive type cannot translated sql query.
you should first fetch database memory , join 2 lists in memory.
for example:
var vla = (from cir in phoenixentities.componentinroles.tolist() join role in roles on cir.roleid equals role.roleid cir.componentid == cmpent1.componentid select role).tolist();
i hope helped
Comments
Post a Comment