开发者

Datatable group by issue r.Field<T>

开发者 https://www.devze.com 2023-03-05 06:24 出处:网络
i was searching datatable group by option and found solution in stackoverflow. DataTable t = // var groups = t.AsEnumerable()

i was searching datatable group by option and found solution in stackoverflow.

DataTable t = //
var groups = t.AsEnumerable()
    .GroupBy(r => r.Field<T>("col开发者_JAVA百科umnName"))

What does this mean... r.Field<T>. why Field<T>?

Can't I here specify r.Field<Customer>.


read http://blogs.msdn.com/b/adonet/archive/2007/02/05/type-safety-linq-to-datasets-part-2.aspx

Edited:

1) why Field?

Field<T> method : DataTable is not typed one,the values to be saved as object. so the Field method returns the value of the column with generic type parameter, thus enable type checking.

If it is a typed DataTable then you can Field<Customer.ID>

    -
0

精彩评论

暂无评论...
验证码 换一张
取 消