Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.IDataReader'

后端 未结 1 1100
北恋
北恋 2021-01-19 11:17

When trying to create this linq statement. I ran into the following error:

Unable to cast object of type \'System.Data.Common.DataRecordInternal\' t

相关标签:
1条回答
  • 2021-01-19 11:38

    Try reader.Cast<DbDataRecord> or reader.Cast<IDataRecord> instead:

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

    IDataRecord Interface

    Provides access to the column values within each row for a DataReader, and is implemented by .NET Framework data providers that access relational databases.

    0 讨论(0)
提交回复
热议问题