0

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?

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
Xennon
  • 25
  • 5

1 Answers1

2

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)
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • It is not possible for me to split the program into different classes, because I need System.Data.DataSetExtensions in this sub. It would require too much memory if I transfer the datatable from the Linq Expression to an other sub outside of this class. Is it possible for me to deactivate the 'where' in DataSetExtensions? – Xennon Oct 14 '11 at 14:12
  • I don't understand what you mean with "too much memory if you transfer the datatable". Simply calling a method on another class with the data table as an argument doesn't make copies of your table or otherwise uses up memory. To be exact, even using the Where-Extension does nothing else but call a static method on a different class and passing the datatable as an argument. – Dennis Traub Oct 14 '11 at 14:18
  • Thank you for your efforts. You mean something like this? `ds.Sales.System.Linq.Dynamic.Where(strWhere)` I have already tried without success. – Xennon Oct 14 '11 at 14:45
  • Thanks, this is the solution: `Dim filterQuery = System.Linq.Dynamic.DynamicQueryable.Where(ds.Sales.AsEnumerable, strWhere)` – Xennon Oct 14 '11 at 15:00