是否可以为非强类型数据表构建动态LINQ查询?(Is it possible to build dynamic LINQ queries to non-strongly type datatables?)
使用LINQ ,我一直在尝试使用System.Linq.Dynamic库来动态查询数据表。 问题是它不是强类型的,而select的扩展方法是期望IEnumerable作为源。
有办法解决这个问题吗? 示例代码:
var query = dataSet.Tables[0].AsEnumerable().Select("new(Regional)");Using LINQ, I've been trying to use the System.Linq.Dynamic library in order to query a datatable dynamically. The problem is that it's not strongly typed, and the extension method for select is expecting an IEnumerable as the source.
Is there a way to work around this? Example code:
var query = dataSet.Tables[0].AsEnumerable().Select("new(Regional)");最满意答案
AsEnumerable返回一个EnumerableRowCollection<DataRow> ,因此Select扩展方法应该可以正常处理AsEnumerable的结果...
例如 :
var query = dataSet.Tables[0].AsEnumerable().Select(row => row.Field<string>("Regional"));I found a solution here. I know this approach is might not be good when talking about performance, but it works for what I want
HOW TO: Implement a DataSet GROUP BY Helper Class in Visual C# .NET
更多推荐
发布评论