-
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
Align property discovery convention with type mapping #2588
Comments
One thing to keep in mind here is that even though type support varies by provider, the current fashion is to build one model to rule them all. We all know that fashions change rapidly, but assuming we continue with one model, then it means every provider should get a chance to decide where a property can be mapped or not. We also need to decide what to do when a property can't be mapped. The behavior in the old stack and the current behavior in EF7 is to ignore properties of types that can't be mapped. I think we should probably change this because it is usually not what people want--especially for primitive/simple types. I'll file an issue for this. (Note we can still choose to ignore properties for other reasons, such as read-only properties.) Bringing these two things together, should we fail if a given property type cannot be mapped by any of the providers for which we are building the model? Based on the one model logic (that it represents your domain and should be structurally equivalent across providers) I think we probably should. |
Agreed!
I like that option. I believe when we add custom type mapping customers that hit a scenario like this will be able to tweak the mapping for that specific provider so as long as they can come up with a mapping that works this will become totally ok. |
+1 for this, any chance you'll get this into the RTM? If not, users can still use the fluent API (or annotations) to include a property with a non-standard type in the model, as long as the type mapper supports it, right? |
This issue describes what @smitpatel has done in #3387 (throwing when the property cannot be mapped as described in #2612 is only one aspect of it) so we moved it back from the backlog to rc1. |
@smitpatel there a few issues @ajcvickers raised in the PR that we need to follow up on. Can you file a new bug for those? |
Details of changes for provider writers To throw exception for unmapped property, new convention
For Provider writers, they need to update provider specific type mapper and convention set builder, everything else should wire up by itself. To answer @roji 's question - User can still use Fluent API to add property with non-standard type and specify which column type to use for it. |
Thanks for the details @smitpatel! |
@roji - Regarding your question - We decided today that CLR types which are not supported by type mapper cannot be added to the model. (even if there is column type specified since conversion from CLR type to specified column type and vice-versa is not known to EF). So for any non-standard type, as long as type mapper says that such CLR type can be mapped to the database, it can be added. |
OK, sounds good. I'll be re-implementing the Npgsql type mapper very soon and will post if there are any difficulties. |
When a TEntity CLR type is passed to
ModelBuilder.Entity<TEntity>()
we need a mechanism to identify scalar properties and navigation properties (plus complex type/value object properties in the future) on it.Currently
PropertyDiscoveryConvention
usesSharedTypeExtensions.IsPrimitive()
to identify "primitive" properties on a given entity's CLR type.Unfortunately the heuristic perpetuates the idea of a canonical set of primitive types supported by EF, while in reality type support should vary on a provider basis (e.g. while SQL Server does not support many unsigned int types, other providers do not support DateTimeOffset and some providers may have native support for types that EF does not know about, etc.) and in the long term even become extensible via user-provided custom type mappers.
One way to improve this would be to have an API that the convention can use to find out if a specific property type can be handled by the "current" type mapping (i.e. the provider's type mapping and in the future, any registered custom type mappers).
Note that this approach assumes that at model building time we would have access to type mapping (which I am not sure is currently possible).
The text was updated successfully, but these errors were encountered: