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

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

问题描述

我有一个 DataSet ,我想将 DataSet 转换为列表< T> ;

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

T型对象

如何转换我的 DataSet ?它有10列,全部10个属性我的对象有,它返回超过15000行。我想将该数据集返回到 List< obj> 并循环它如何做到这一点?

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

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

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