c# - I'm getting exception when query with Linq to Entity? -


here exception

unable create constant value of type 'system.collections.generic.ienumerable`1'. primitive types ('such int32, string, , guid') supported in context.

here code

list<int> items = new list<int>(){1,5,7,14};  var selecteditems = (from u in _entities.userinfo                      join type in items on u.typeid equals  type                      u.userid == userid                      select new userclass                      {                          firstname = u.firstname,                          lastname = u.lastname                      }).tolist(); 

any ideas can cause exception? , maybe workaround?

for ef4
rid of join on items , add && items.contains(u.typeid) clause.

int[] items = new[] { 1, 5, 7, 14 };  var selecteditems = (from u in _entities.userinfo                          u.userid == userid && items.contains(u.typeid)                         select new userclass {                                             firstname = u.firstname,                                              lastname = u.lastname,                                              email = ul.email                                     }).tolist(); 

for ef1
ef1 not support collection-valued parameters (i.e. contains()) post contains code utility method called buildcontainsexpression can used around restriction.

update
updated answer reflect comments craig stuntz regarding solutions ef1 & ef4


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -