无法将类型为"System.Data.Common.DataRecordInternal"的对象转换为类型为"System.Data.IDataReader"的对象 [英] Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.IDataReader'
问题描述
尝试创建此 linq语句时.我遇到以下错误:
When trying to create this linq statement. I ran into the following error:
无法转换类型为'System.Data.Common.DataRecordInternal'的对象 键入"System.Data.IDataReader"
Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.IDataReader'
这是我根据@SLaks 有希望的答案所做的事情.
This is what I'm doing per @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"] });
提供对DataReader每行中列值的访问, 并由可访问的.NET Framework数据提供程序实现 关系数据库.
Provides access to the column values within each row for a DataReader, and is implemented by .NET Framework data providers that access relational databases.
这篇关于无法将类型为"System.Data.Common.DataRecordInternal"的对象转换为类型为"System.Data.IDataReader"的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!