tags:

views:

282

answers:

1

I am looking for sample linq code snippet which uses System.Linq.Dynamic against a datatable.

Dim entities = (From ent In dt.AsEnumerable().Where(String.Format("IsUSFederal == {0}", "true")) _
Select Description = ent("Description"), Acronym = ent("Acronym")).ToList

I am getting an error "there is no accessible Where can be called with these arguments". I have included the DynamicLinq.vb file and the application compiles fine (aside from this error). I have included Imports System.Linq.Dynamic but it doesn't appear to be working.

Any ideas? thx

+2  A: 

The Enumerable.Where takes a Func(Of TSource, Boolean) as argument and your passing a String.

(update)

Didn't catch the Dynamic library part ... sorry. I think you need to do this:

dt.AsQueryable()

Because the extension methods on the library are defined as:

<Extension()> _
Public Function Where(ByVal source As IQueryable, ByVal predicate As String, 
                      ByVal ParamArray values() As Object) As IQueryable
bruno conde
I am trying to use the linq extensions in http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspxbut something is not quite right as it seems the .Where in the extension is not being used
David
@David, see my update
bruno conde