System.Linq.Dynamic ´s .Where will be misinterpreted

602 Views Asked by At

I've build a large program with many references. F.e.:

  • System.Data.DataSetExtensions
  • System.Linq.Dynamic

I've to write a Dynamic Linq Expression:

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

In my case:

Dim query As IEnumerable = ds.Sales.Where(strWhere)

But with System.Data.DataSetExtensions Where is misinterpreted. The compiler expects (Datarow, Integer, Boolean). If I delete System.Data.DataSetExtensions everything is ok with this expression, but I get many other errors, so I need this reference.

What can I do that the Where is interpreted correctly?

1

There are 1 best solutions below

4
Dennis Traub On BEST ANSWER

Is the large programm all in one file?

If not done already, split up your program into classes, then put each class into it's own file. Then only use the required references in every file.

Maybe this way you will be able to resolve the namespace conflict.

If for some reason you absolutely need both conflicting namespaces and can't resolve the ambiguity, you can directly call the extension method. Basically the extension method is just another static method on another class. ds.Sales.Where(strWhere) is only syntactic sugar for that method call.

An example:

ds.Sales.AsEnumerable().Where(yourCondition)

Would translate to

EnumerableRowCollectionExtensions.Where(ds.Sales.AsEnumerable(), yourCondition)