我已经构建了一个包含许多参考文献的大型程序。 Fe:
- System.Data.DataSetExtensions
- System.Linq.Dynamic
我必须编写一个动态Linq表达式:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
就我而言:
Dim query As IEnumerable = ds.Sales.Where(strWhere)
但是 System.Data.DataSetExtensions
Where
被误解了。编译器需要 (Datarow, Integer, Boolean)
。如果我删除 System.Data.DataSetExtensions ,此表达式一切正常,但我会收到许多其他错误,因此我需要此引用。
我该怎么做才能正确解释 Where
?
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)
大型程序都在一个文件中吗?
如果尚未完成,请将程序拆分为类,然后将每个类放入其自己的文件中。然后仅在每个文件中使用所需的引用。
也许这样你就能解决命名空间冲突。
如果由于某种原因您绝对需要两个冲突的命名空间并且无法解决歧义,则可以直接调用扩展方法。基本上,扩展方法只是另一个类上的另一个静态方法。
ds.Sales.Where(strWhere)
只是该方法调用的语法糖。一个例子:
会翻译成
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:
Would translate to