-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLite affinity fallback is wrong: fallback to blob instead of numeric #31915
Comments
/cc @bricelam |
I looked a bit deeper. In my code I just implemented the affinity resolution according to SQLite specs before calling this EF API, where I map non-standard storage types to |
This was a conscious decision made in 3.0 to fallback to BLOB instead of INTEGER/REAL (see #13841 and #13253).
We disagree. The chances of an unknown type being long or double seem a lot lower than it being something like string or byte[]. Since byte[] is the only format that's guaranteed to be lossless, we went with that.
This is exactly what we've done in 8.0 when reverse engineering a model from an existing database. See #8824 |
I do not understand the reasoning behind this phrase:
According to the SQLite docs a present (any non-empty string) type that is not resolved to any affinity is treated as Thanks a lot for the links! I would not have found them easily. Now I understand what's going and why in EF code. I have a workaround for my needs so this could be closed. |
An affinity of numeric is not the same as a static type of integer or real. ADO.NET is statically typed. Saying that a column with an unknown type is always numeric is different than saying it has a numeric affinity. Even though SQLite has type affinity, at the end of the day, it's dynamically typed and will work with any type inside the column regardless of affinity. |
This line creates a problem when trying to get a .NET type from SQLite storage type.
efcore/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs
Lines 169 to 171 in 36b5c81
From this SQLite docs item 3.1.5:
Otherwise, the affinity is NUMERIC
. That is, when_typeRules
cannot resolve a type then the type should benumeric
. However, the current implementation falls back toBlob
. Item 3.1.3 says that the blob should only be used as a fallback when the storage type is absent:if no type is specified then the column has affinity BLOB
It's funny that
numeric
is resolved toblob
there. 🤦 Also problematic are:TIMESTAMP
,DECIMAL(5,2)
.Found this by manually scaffolding SQLite Sakila DB (e.g. Actor, Payment tables). Specifically, using
IRelationalTypeMappingSource.FindMapping(DatabaseColumn.StoreType)
.The text was updated successfully, but these errors were encountered: