我有一个数据DataReader,我希望将其转换为List<T>.对此有什么简单的解决方案?
例如,在CustomerEntity类中,我有CustomerId和CustomerName属性.如果我的DataReader将这两列作为数据返回,那么我该如何将其转换为List<CustomerEntity>.
在尝试创建此 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)