vb.net - Enumeration Type exception when attempting to filter a LINQ query -


i'm trying generate grid end-users can filter data using several inputs.

to i'm attempting filter initial linq entities object follows:

dim servhist iqueryable(of serviceshistory) = db.serviceshistories  if cboproperty.editvalue <> nothing     servhist = servhist.where(function(p) p.propid = clng(cboproperty.editvalue)) end if  grdservhist.datasource = servhist.tolist() 

however when attempt filter query, following error message when attempting enumerate collection: "unable create constant value of type 'system.object'. primitive types or enumeration types supported in context."

i'm @ loss. i've done w/out problem using c#, unfortunately cannot go w/ vb.

this issue capture in closure in linq expression.

in english, means trying pass clng(cboproperty.editvalue) linq expression. legal. when linq entity framework looks @ that, can't convert sql. expression contains:

  1. a .net class (most winform control suspect)
  2. a property call on .net class
  3. a .net conversion call on result of .net class.

poor linq2ef can't figure stuff out! work.

dim servhist iqueryable(of serviceshistory) = db.serviceshistories  if cboproperty.editvalue <> nothing     dim editvalue = clng(cboproperty.editvalue)     servhist = servhist.where(function(p) p.propid = editvalue) end if  grdservhist.datasource = servhist.tolist() 

now looks same. if ask linq ninja tell 2 different, since have converted clng(cboproperty.editvalue) linq expression function call.

personally in 2 minds how lambda expressions have same syntax lambda functions, leading these exceptions.

btw prefer queries in form...

dim editvalue = clng(cboproperty.editvalue) dim servhist iqueryable(of serviceshistory) = _     db.serviceshistories.where(function(p) p.propid = editvalue or editvalue nothing) grdservhist.datasource = servhist.tolist() 

this allows refactor iqueryable compiled query.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -