Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Issue: [RTM] Providers may expect to convert types read through their data readers [1502]

$
0
0
Prior to EF6, EF would read data from columns using the provider's DbDataReader GetXxx() methods, where Xxx is something like Int32, String, etc. This gave providers a hint as to the type that is expected for the data in that column. So, for example, for a database that does not have a native long type it might choose to store long types as decimals. Then in the GetInt64 method the data reader would convert the decimal into a long before returning it.

EF6 introduced buffering and as part of this EF now reads all values for a row using GetValues. EF no longer uses the GetXxx methods. Using the example above this means that the decimal object is stored by EF without giving the provider a chance to convert it into the expected long. EF then tries to use the value as a long and this results in an exception.

See https://entityframework.codeplex.com/discussions/452283 for the discussion that originated this item.

Exception:
```
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Specified cast is not valid.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Core.Objects.Internal.BufferedDataRecord.GetFieldValue[T](Int32 ordinal)
at System.Data.Entity.Core.Objects.Internal.BufferedDataRecord.GetInt64(Int32 ordinal)
at System.Data.Entity.Core.Objects.Internal.BufferedDataReader.GetInt64(Int32 ordinal)
InnerException:
```
Comments: Fixed in changeset ae4c2549b19703ef1df37b76f4e0a4b787d493a9

Viewing all articles
Browse latest Browse all 10318

Trending Articles