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



这就是我按照 @SLaks promising answer 所做的。

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

最佳答案

尝试 reader.Cast<DbDataRecord>reader.Cast<IDataRecord> 代替:

IEnumerable<TypeData> typeData = reader.Cast<IDataRecord>()
   .Select(dr => new TypeData { Type = (string)dr["type"] });

IDataRecord Interface

关于c# - 无法将 'System.Data.Common.DataRecordInternal' 类型的对象转换为 'System.Data.IDataReader' 类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12500763/

10-11 01:01