You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Doing an initial discovery of the model based only on DbSet roots was a reasonable approach when it was reasonably easy to distinguish likely scalar properties from likely navigation properties. However, as we allow more an more types to be mapped it has become increasingly problematic to
Exclude a type as an entity type and therefore avoid trying to bring it and all its properties into the model
Revert a type from being an entity type when a value converter is found or the type is ignored.
This results in both bugs and additional overhead.
Therefore, this issue is about finding ways to enhance model building so that it can more efficiently figure out what is an entity type and what is not. Some ideas:
Some up-front configuration that defines either types that are entity types, or types that are not entity types. This would be provided before model building begins, possibly using model customization or lifecycle hooks.
Up-front configuration for value converters, which would provide partial info on types that are not entity types.
The up-front configuration should be non-interactive (i.e. no conventions will be running before it is finished and there won't be a way to get the current model). Thus it requires new API separate from ModelBuilder (but still following the same patterns).
Calling these methods will have no immediate effect on the model. But when a type is discovered by convention any configuration specified for it or any base type or implemented interface will be applied at that point. The configuration specified using ModelConfigurationBuilder is considered Explicit
Last one wins for multiple conflicting configurations for the same type.
An exception is thrown when base types have conflicting configurations, unless overridden by Fluent API.
Activity
ajcvickers commentedon Jun 7, 2018
The initial work here is to investigate and have some initial design discussions about ways we could go.
AndriySvyryd commentedon Dec 18, 2018
The up-front configuration should be non-interactive (i.e. no conventions will be running before it is finished and there won't be a way to get the current model). Thus it requires new API separate from
ModelBuilder(but still following the same patterns).Proposal:
DbContext.OnModelBuiderCreating(ModelConfigurationBuilder configurationBuilder)Related to #6787, #3867, #10784, #20418
[-]Consider architecture changes to mitigate open model[/-][+]Pre-convention model configuration[/+]16 remaining items
AndriySvyryd commentedon May 18, 2021
A more detailed proposal:
Calling these methods will have no immediate effect on the model. But when a type is discovered by convention any configuration specified for it or any base type or implemented interface will be applied at that point. The configuration specified using
ModelConfigurationBuilderis consideredExplicitLast one wins for multiple conflicting configurations for the same type.
An exception is thrown when base types have conflicting configurations, unless overridden by Fluent API.
Add pre-convention model configuration.
Add pre-convention model configuration infrastructure
Add pre-convention model configuration infrastructure