-
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
Pre-convention model configuration #12229
Comments
The initial work here is to investigate and have some initial design discussions about ways we could go. |
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 Proposal: |
Also |
A more detailed proposal: protected internal virtual void ConfigureConventions(ModelConfigurationBuilder configurationBuilder); public class ModelConfigurationBuilder
{
public ModelConfigurationBuilder(ConventionSet conventions);
public ConventionSetBuilder Conventions { get; }
public virtual EntityTypesConfigurationBuilder Entities();
public virtual ModelConfigurationBuilder Entities(Action<EntityTypesConfigurationBuilder> buildAction);
public virtual EntityTypesConfigurationBuilder Entities(Type type);
public virtual ModelConfigurationBuilder Entities(Type type, Action<EntityTypesConfigurationBuilder> buildAction);
public virtual EntityTypesConfigurationBuilder SharedTypeEntities();
public virtual ModelConfigurationBuilder SharedTypeEntities(Action<EntityTypesConfigurationBuilder> buildAction);
public virtual EntityTypesConfigurationBuilder SharedTypeEntities(Type type);
public virtual ModelConfigurationBuilder SharedTypeEntities(Type type, Action<EntityTypesConfigurationBuilder> buildAction);
public virtual OwnedEntityTypesConfigurationBuilder OwnedEntities();
public virtual ModelConfigurationBuilder OwnedEntities(Type type);
public virtual OwnedEntityTypesConfigurationBuilder OwnedEntities(Type type);
public virtual ModelConfigurationBuilder OwnedEntities(Type type, Action<OwnedEntityTypesConfigurationBuilder> buildAction);
public virtual ModelConfigurationBuilder IgnoreAny(Type type);
public virtual PropertiesConfigurationBuilder Properties(Type propertyType);
public virtual ModelConfigurationBuilder Properties(Type propertyType, Action<PropertiesConfigurationBuilder> buildAction);
public virtual ServicePropertiesConfigurationBuilder ServiceProperties(Type propertyType);
public virtual ModelConfigurationBuilder ServiceProperties(Type propertyType, Action<ServicePropertiesConfigurationBuilder> buildAction);
public virtual ModelBuilder InitializeModelBuilder(ModelDependencies modelDependencies);
} public class PropertiesConfigurationBuilder
{
[EntityFrameworkInternal]
public PropertiesConfigurationBuilder(PropertiesConfiguration property);
public virtual PropertiesConfigurationBuilder HaveAnnotation(string annotation, object? value);
public virtual PropertiesConfigurationBuilder HaveMaxLength(int maxLength);
public virtual PropertiesConfigurationBuilder HavePrecision(int precision, int scale);
public virtual PropertiesConfigurationBuilder HavePrecision(int precision);
public virtual PropertiesConfigurationBuilder AreUnicode(bool unicode = true);
public virtual PropertiesConfigurationBuilder HaveConversion(Type providerClrType);
public virtual PropertiesConfigurationBuilder HaveConversion(Type converterType, Type comparerType);
} 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 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. |
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
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:
The text was updated successfully, but these errors were encountered: