使用 linq 将数据集列表 <T> [英] dataset to List<T>using linq

查看:16
本文介绍了使用 linq 将数据集列表 <T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a DataSet and I want to convert the DataSet into List<T>

T - type object

How convert my DataSet? It has 10 columns, with all 10 properties my object has and it's returning over 15000 rows. I want to return that dataset into List<obj> and loop it how do I do that?

解决方案

This is pretty much the same as the other answers, but introduces strongly-typed columns.

var myData = ds.Tables[0].AsEnumerable().Select(r => new {
    column1 = r.Field<string>("column1"),
    column2 = r.Field<int>("column2"), 
    column3 = r.Field<decimal?>("column3")
});
var list = myData.ToList(); // For if you really need a List and not IEnumerable

这篇关于使用 linq 将数据集列表 &lt;T&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆