-
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
Allow applications to create model building conventions (aka public conventions) #214
Comments
This was useful for me in the following Scenarios:
Doing this once I was able to govern the entity definitions without requiring explicit entity declaration. I'm not advocating the same implementation, but do feel custom/override conventions are valuable. Cheers, Steve |
Some of these types of things can be achieved by iterating over the model that is created by convention. This was not possible in EF6 because we collected a set of configuration during OnModelCreating and then used that plus conventions to build the model. But in EF Core we build an initial model from conventions and then pass that to OnModelCreating. Of course, this means you need to be mindful of ordering. For example, if a type wasn't included in the model by convention, then you need to make sure you add it before you iterate over the model and assign table names. Here is an example of appending an protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
modelBuilder.Entity(entity.Name).ToTable(entity.Name + "s");
}
} |
Thanks for the info Rowan, I'll just need to explicitly load my entities in this method for my domain assembly: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var entityTypes = myDomainAssembly.DefinedTypes
.Where(ti => ti.IsClass && ti.IsPublic && !ti.IsAbstract && !ti.IsNested)
foreach (var entityType in entityTypes)
{
modelBuilder.Entity(entityType).ToTable(entity.Name + "s");
}
} This makes me think that perhaps an Steve |
I see that this issue is not a priority issue, but will the custom conventions be implemented before RC2, or just before RTM? (I hope it will be at least in RTM) |
According to the current roadmap it will be in 7.0.2 (?) https://github.com/aspnet/EntityFramework/wiki/Roadmap |
Ohh I missed this. Thank you. |
Consider a way to get from IMutableEntityType (or similar) to the InternalEntityTypeBuilder (or similar) so that changes can be flagged as "by convention" when making changes to an IMutableEntityType. See comments on PR #4688. |
…ns and tracking objects modified by conventions. When set on ConventionDispatcher ConventionScope captures the conventions to be executed. ConventionBatch sets a ConventionScope and executed the stored conventions when it's run or disposed. When conventions captured in a ConventionScope are executed any triggered conventions are captured in a new ConventionScope to avoid keeping all the convention chain on the stack. This changes the order of convention execution which exposed some issues in code and tests Allow specifying the dependend end without specifying the FK properties, Throw when the same property is specified several times when adding a key, foreign key or indexes. Remove Mock usage from ConventionDispatcherTest Part of #214
This comment was marked as off-topic.
This comment was marked as off-topic.
hello, I come from this #27400 |
QueryFilter
,DefiningQuery
,IsEagerLoaded
,IsShadowProperty
,IsIndexedProperty
,BeforeSaveBehavior
AfterSaveBehavior
to extension methods.SetField
would change the shadowness of a property or the name of the identifyingMemberInfo
.GetContainingPrimaryKey
toFindContainingPrimaryKey
.SetField
on a shadow or a field-only property.IConventionModelBuilder
. This will allow cleaner API, without the explicitConfigurationSource
parameter.Property
vsIProperty
vsstring
vsPropertyInfo
)RelationalAnnotations
andRelationalAnnotationsBuilder
to Core.SqlServerPropertyBuilderAnnotations.ColumnName
.Apply
methods to be more descriptive and make the return types consistent, still allowing to stop the execution of the following conventions.CoreConventionSetBuilderDependencies
to the constructor of all conventions.ModelCustomizer
to a convention.SqlServerValueGenerationStrategy.None
value that can be used to override the model default.PropertyMetadataChanged()
calls and don't cache indexes while the model is mutable.List
onConventionSet
Conventions
property ofConventionSetBuilder
type toModelConfigurationBuilder
with methods to add/remove a conventionThe text was updated successfully, but these errors were encountered: