无法将类型为"System.Data.Common.DataRecordInternal"的对象转换为类型为"System.Data.IDataReader"的对象 [英] Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.IDataReader'

查看:316
本文介绍了无法将类型为"System.Data.Common.DataRecordInternal"的对象转换为类型为"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"] });

IDataRecord界面

提供对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屋!

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