相关疑难解决方法(0)

如何轻松将DataReader转换为List <T>?

我有一个数据DataReader,我希望将其转换为List<T>.对此有什么简单的解决方案?

例如,在CustomerEntity类中,我有CustomerId和CustomerName属性.如果我的DataReader将这两列作为数据返回,那么我该如何将其转换为List<CustomerEntity>.

c# datareader generic-list

112
推荐指数
8
解决办法
26万
查看次数

无法将"System.Data.Common.DataRecordInternal"类型的对象强制转换为"System.Data.IDataReader"类型

在尝试创建 linq语句时.我遇到了以下错误:

无法将"System.Data.Common.DataRecordInternal"类型的对象强制转换为"System.Data.IDataReader"类型

这是我正在做的@SLaks 有希望的答案.

List<TypeData> = reader.Cast<IDataReader>()
   .Select(dr => new TypeData { Type = (string)dr["type"] })                
   .ToList();
Run Code Online (Sandbox Code Playgroud)

c# linq

4
推荐指数
1
解决办法
6371
查看次数

标签 统计

c# ×2

datareader ×1

generic-list ×1

linq ×1