When trying to create this linq statement. I ran into the following error:
Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.IDataReader'
This is what I'm doing per @SLaks promising answer.
List<TypeData> = reader.Cast<IDataReader>()
.Select(dr => new TypeData { Type = (string)dr["type"] })
.ToList();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With