Skip to content
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

Add sugar methods to ConventionSet #28601

Merged
1 commit merged into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,101 +33,17 @@ public override ConventionSet CreateConventionSet()
{
var conventionSet = base.CreateConventionSet();

conventionSet.ModelInitializedConventions.Add(new ContextContainerConvention(Dependencies));

conventionSet.ModelFinalizingConventions.Add(new ETagPropertyConvention());

var storeKeyConvention = new StoreKeyConvention(Dependencies);
var discriminatorConvention = new CosmosDiscriminatorConvention(Dependencies);
KeyDiscoveryConvention keyDiscoveryConvention = new CosmosKeyDiscoveryConvention(Dependencies);
InversePropertyAttributeConvention inversePropertyAttributeConvention =
new CosmosInversePropertyAttributeConvention(Dependencies);
RelationshipDiscoveryConvention relationshipDiscoveryConvention =
new CosmosRelationshipDiscoveryConvention(Dependencies);
conventionSet.EntityTypeAddedConventions.Add(storeKeyConvention);
conventionSet.EntityTypeAddedConventions.Add(discriminatorConvention);
ReplaceConvention(conventionSet.EntityTypeAddedConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.EntityTypeAddedConventions, inversePropertyAttributeConvention);
ReplaceConvention(conventionSet.EntityTypeAddedConventions, relationshipDiscoveryConvention);

ReplaceConvention(conventionSet.EntityTypeIgnoredConventions, relationshipDiscoveryConvention);

ReplaceConvention(conventionSet.EntityTypeRemovedConventions, (DiscriminatorConvention)discriminatorConvention);
ReplaceConvention(conventionSet.EntityTypeRemovedConventions, inversePropertyAttributeConvention);

ValueGenerationConvention valueGenerationConvention = new CosmosValueGenerationConvention(Dependencies);
conventionSet.EntityTypeBaseTypeChangedConventions.Add(storeKeyConvention);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGenerationConvention);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, (DiscriminatorConvention)discriminatorConvention);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, inversePropertyAttributeConvention);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, relationshipDiscoveryConvention);

ReplaceConvention(conventionSet.EntityTypeMemberIgnoredConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.EntityTypeMemberIgnoredConventions, inversePropertyAttributeConvention);
ReplaceConvention(conventionSet.EntityTypeMemberIgnoredConventions, relationshipDiscoveryConvention);

conventionSet.EntityTypePrimaryKeyChangedConventions.Add(storeKeyConvention);
ReplaceConvention(conventionSet.EntityTypePrimaryKeyChangedConventions, valueGenerationConvention);

conventionSet.KeyAddedConventions.Add(storeKeyConvention);

conventionSet.KeyRemovedConventions.Add(storeKeyConvention);
ReplaceConvention(conventionSet.KeyRemovedConventions, keyDiscoveryConvention);

ReplaceConvention(conventionSet.ForeignKeyAddedConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.ForeignKeyAddedConventions, valueGenerationConvention);

ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, relationshipDiscoveryConvention);
conventionSet.ForeignKeyRemovedConventions.Add(discriminatorConvention);
conventionSet.ForeignKeyRemovedConventions.Add(storeKeyConvention);
ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, valueGenerationConvention);

ReplaceConvention(conventionSet.ForeignKeyPropertiesChangedConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.ForeignKeyPropertiesChangedConventions, valueGenerationConvention);

ReplaceConvention(conventionSet.ForeignKeyUniquenessChangedConventions, keyDiscoveryConvention);

conventionSet.ForeignKeyOwnershipChangedConventions.Add(discriminatorConvention);
conventionSet.ForeignKeyOwnershipChangedConventions.Add(storeKeyConvention);
ReplaceConvention(conventionSet.ForeignKeyOwnershipChangedConventions, keyDiscoveryConvention);
ReplaceConvention(conventionSet.ForeignKeyOwnershipChangedConventions, valueGenerationConvention);
ReplaceConvention(conventionSet.ForeignKeyOwnershipChangedConventions, relationshipDiscoveryConvention);

ReplaceConvention(conventionSet.ForeignKeyNullNavigationSetConventions, relationshipDiscoveryConvention);

ReplaceConvention(conventionSet.NavigationAddedConventions, inversePropertyAttributeConvention);
ReplaceConvention(conventionSet.NavigationAddedConventions, relationshipDiscoveryConvention);

ReplaceConvention(conventionSet.NavigationRemovedConventions, relationshipDiscoveryConvention);

ManyToManyJoinEntityTypeConvention manyToManyJoinEntityTypeConvention =
new CosmosManyToManyJoinEntityTypeConvention(Dependencies);
ReplaceConvention(conventionSet.SkipNavigationAddedConventions, manyToManyJoinEntityTypeConvention);

ReplaceConvention(conventionSet.SkipNavigationRemovedConventions, manyToManyJoinEntityTypeConvention);

ReplaceConvention(conventionSet.SkipNavigationInverseChangedConventions, manyToManyJoinEntityTypeConvention);

ReplaceConvention(conventionSet.SkipNavigationForeignKeyChangedConventions, manyToManyJoinEntityTypeConvention);

conventionSet.EntityTypeAnnotationChangedConventions.Add(discriminatorConvention);
conventionSet.EntityTypeAnnotationChangedConventions.Add(storeKeyConvention);
conventionSet.EntityTypeAnnotationChangedConventions.Add((CosmosValueGenerationConvention)valueGenerationConvention);
conventionSet.EntityTypeAnnotationChangedConventions.Add((CosmosKeyDiscoveryConvention)keyDiscoveryConvention);
conventionSet.EntityTypeAnnotationChangedConventions.Add(
(CosmosManyToManyJoinEntityTypeConvention)manyToManyJoinEntityTypeConvention);

ReplaceConvention(conventionSet.PropertyAddedConventions, keyDiscoveryConvention);

conventionSet.PropertyAnnotationChangedConventions.Add(storeKeyConvention);

ReplaceConvention(conventionSet.ModelFinalizingConventions, inversePropertyAttributeConvention);

ReplaceConvention(
conventionSet.ModelFinalizedConventions,
(RuntimeModelConvention)new CosmosRuntimeModelConvention(Dependencies));
conventionSet.Add(new ContextContainerConvention(Dependencies));
conventionSet.Add(new ETagPropertyConvention());
conventionSet.Add(new StoreKeyConvention(Dependencies));

conventionSet.Replace<ValueGenerationConvention>(new CosmosValueGenerationConvention(Dependencies));
conventionSet.Replace<KeyDiscoveryConvention>(new CosmosKeyDiscoveryConvention(Dependencies));
conventionSet.Replace<InversePropertyAttributeConvention>(new CosmosInversePropertyAttributeConvention(Dependencies));
conventionSet.Replace<RelationshipDiscoveryConvention>(new CosmosRelationshipDiscoveryConvention(Dependencies));
conventionSet.Replace<DiscriminatorConvention>(new CosmosDiscriminatorConvention(Dependencies));
conventionSet.Replace<ManyToManyJoinEntityTypeConvention>(new CosmosManyToManyJoinEntityTypeConvention(Dependencies));
conventionSet.Replace<RuntimeModelConvention>(new CosmosRuntimeModelConvention(Dependencies));

return conventionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override ConventionSet CreateConventionSet()
{
var conventionSet = base.CreateConventionSet();

conventionSet.ModelFinalizingConventions.Add(new DefiningQueryRewritingConvention(Dependencies));
conventionSet.Add(new DefiningQueryRewritingConvention(Dependencies));

return conventionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Microsoft.EntityFrameworkCore.Proxies.Internal;
public class ProxiesConventionSetPlugin : IConventionSetPlugin
{
private readonly IDbContextOptions _options;
private readonly IProxyFactory _proxyFactory;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -21,12 +20,10 @@ public class ProxiesConventionSetPlugin : IConventionSetPlugin
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public ProxiesConventionSetPlugin(
IProxyFactory proxyFactory,
IDbContextOptions options,
LazyLoaderParameterBindingFactoryDependencies lazyLoaderParameterBindingFactoryDependencies,
ProviderConventionSetBuilderDependencies conventionSetBuilderDependencies)
{
_proxyFactory = proxyFactory;
_options = options;
LazyLoaderParameterBindingFactoryDependencies = lazyLoaderParameterBindingFactoryDependencies;
ConventionSetBuilderDependencies = conventionSetBuilderDependencies;
Expand Down Expand Up @@ -63,11 +60,10 @@ public virtual ConventionSet ModifyConventions(ConventionSet conventionSet)
new ProxyChangeTrackingConvention(extension),
typeof(DbSetFindingConvention));

conventionSet.ModelFinalizingConventions.Add(
new ProxyBindingRewriter(
extension,
LazyLoaderParameterBindingFactoryDependencies,
ConventionSetBuilderDependencies));
conventionSet.Add(new ProxyBindingRewriter(
extension,
LazyLoaderParameterBindingFactoryDependencies,
ConventionSetBuilderDependencies));

return conventionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,89 +58,32 @@ public override ConventionSet CreateConventionSet()
{
var conventionSet = base.CreateConventionSet();

var relationalColumnAttributeConvention = new RelationalColumnAttributeConvention(Dependencies, RelationalDependencies);
var relationalCommentAttributeConvention = new RelationalColumnCommentAttributeConvention(Dependencies, RelationalDependencies);
var relationalPropertyJsonPropertyNameAttributeConvention = new RelationalPropertyJsonPropertyNameAttributeConvention(Dependencies, RelationalDependencies);

conventionSet.PropertyAddedConventions.Add(relationalColumnAttributeConvention);
conventionSet.PropertyAddedConventions.Add(relationalCommentAttributeConvention);
conventionSet.PropertyAddedConventions.Add(relationalPropertyJsonPropertyNameAttributeConvention);

var relationalNavigationJsonPropertyNameAttributeConvention = new RelationalNavigationJsonPropertyNameAttributeConvention(Dependencies, RelationalDependencies);
conventionSet.NavigationAddedConventions.Add(relationalNavigationJsonPropertyNameAttributeConvention);

var tableNameFromDbSetConvention = new TableNameFromDbSetConvention(Dependencies, RelationalDependencies);
var entitySplittingConvention = new EntitySplittingConvention(Dependencies, RelationalDependencies);
var checkConstraintConvention = new CheckConstraintConvention(Dependencies, RelationalDependencies);
var triggerConvention = new TriggerConvention(Dependencies, RelationalDependencies);
conventionSet.EntityTypeAddedConventions.Add(new RelationalTableAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.EntityTypeAddedConventions.Add(
new RelationalTableCommentAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.EntityTypeAddedConventions.Add(tableNameFromDbSetConvention);
conventionSet.EntityTypeAddedConventions.Add(entitySplittingConvention);
conventionSet.EntityTypeAddedConventions.Add(checkConstraintConvention);
conventionSet.EntityTypeAddedConventions.Add(triggerConvention);
conventionSet.EntityTypeAddedConventions.Add(new StoredProcedureConvention(Dependencies, RelationalDependencies));

ValueGenerationConvention valueGenerationConvention =
new RelationalValueGenerationConvention(Dependencies, RelationalDependencies);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGenerationConvention);
conventionSet.EntityTypeBaseTypeChangedConventions.Add(tableNameFromDbSetConvention);
conventionSet.EntityTypeBaseTypeChangedConventions.Add(checkConstraintConvention);
conventionSet.EntityTypeBaseTypeChangedConventions.Add(triggerConvention);

conventionSet.EntityTypeAnnotationChangedConventions.Add(tableNameFromDbSetConvention);

var mapToJsonConvention = new RelationalMapToJsonConvention(Dependencies, RelationalDependencies);
conventionSet.EntityTypeAnnotationChangedConventions.Add(mapToJsonConvention);

ReplaceConvention(conventionSet.ForeignKeyPropertiesChangedConventions, valueGenerationConvention);

ReplaceConvention(conventionSet.ForeignKeyOwnershipChangedConventions, valueGenerationConvention);

conventionSet.EntityTypeAnnotationChangedConventions.Add((RelationalValueGenerationConvention)valueGenerationConvention);

ReplaceConvention(conventionSet.EntityTypePrimaryKeyChangedConventions, valueGenerationConvention);

ReplaceConvention(conventionSet.ForeignKeyAddedConventions, valueGenerationConvention);

ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, valueGenerationConvention);

conventionSet.PropertyAddedConventions.Add(new PropertyOverridesConvention(Dependencies, RelationalDependencies));

conventionSet.PropertyFieldChangedConventions.Add(relationalColumnAttributeConvention);
conventionSet.PropertyFieldChangedConventions.Add(relationalCommentAttributeConvention);

var storeGenerationConvention = new StoreGenerationConvention(Dependencies, RelationalDependencies);
conventionSet.PropertyAnnotationChangedConventions.Add(storeGenerationConvention);
conventionSet.PropertyAnnotationChangedConventions.Add((RelationalValueGenerationConvention)valueGenerationConvention);

var dbFunctionAttributeConvention = new RelationalDbFunctionAttributeConvention(Dependencies, RelationalDependencies);
conventionSet.ModelInitializedConventions.Add(dbFunctionAttributeConvention);

// ModelCleanupConvention would remove the entity types added by TableValuedDbFunctionConvention #15898
ConventionSet.AddAfter(
conventionSet.ModelFinalizingConventions,
new TableValuedDbFunctionConvention(Dependencies, RelationalDependencies),
typeof(ModelCleanupConvention));
conventionSet.ModelFinalizingConventions.Add(new TableSharingConcurrencyTokenConvention(Dependencies, RelationalDependencies));
conventionSet.ModelFinalizingConventions.Add(dbFunctionAttributeConvention);
conventionSet.ModelFinalizingConventions.Add(tableNameFromDbSetConvention);
conventionSet.ModelFinalizingConventions.Add(storeGenerationConvention);
conventionSet.ModelFinalizingConventions.Add(entitySplittingConvention);
conventionSet.ModelFinalizingConventions.Add(new EntityTypeHierarchyMappingConvention(Dependencies, RelationalDependencies));
conventionSet.ModelFinalizingConventions.Add(new SequenceUniquificationConvention(Dependencies, RelationalDependencies));
conventionSet.ModelFinalizingConventions.Add(new SharedTableConvention(Dependencies, RelationalDependencies));
ReplaceConvention(
conventionSet.ModelFinalizingConventions,
(QueryFilterRewritingConvention)new RelationalQueryFilterRewritingConvention(
Dependencies, RelationalDependencies));

conventionSet.ModelFinalizingConventions.Add(mapToJsonConvention);

ReplaceConvention(
conventionSet.ModelFinalizedConventions,
(RuntimeModelConvention)new RelationalRuntimeModelConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalColumnAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalColumnCommentAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalTableAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalTableCommentAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalDbFunctionAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalPropertyJsonPropertyNameAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalNavigationJsonPropertyNameAttributeConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new TableSharingConcurrencyTokenConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new TableNameFromDbSetConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new PropertyOverridesConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new CheckConstraintConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new TriggerConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new StoredProcedureConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new TableValuedDbFunctionConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new StoreGenerationConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new EntitySplittingConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new EntityTypeHierarchyMappingConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new SequenceUniquificationConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new SharedTableConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalMapToJsonConvention(Dependencies, RelationalDependencies));

conventionSet.Replace<ValueGenerationConvention>(
new RelationalValueGenerationConvention(Dependencies, RelationalDependencies));
conventionSet.Replace<QueryFilterRewritingConvention>(
new RelationalQueryFilterRewritingConvention(Dependencies, RelationalDependencies));
conventionSet.Replace<RuntimeModelConvention>(new RelationalRuntimeModelConvention(Dependencies, RelationalDependencies));

return conventionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions;
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-conventions">Model building conventions</see> for more information and examples.
/// </remarks>
public class RelationalNavigationJsonPropertyNameAttributeConvention : NavigationAttributeConventionBase<JsonPropertyNameAttribute>
public class RelationalNavigationJsonPropertyNameAttributeConvention :
NavigationAttributeConventionBase<JsonPropertyNameAttribute>,
INavigationAddedConvention
{
/// <summary>
/// Creates a new instance of <see cref="RelationalNavigationJsonPropertyNameAttributeConvention" />.
Expand Down
5 changes: 2 additions & 3 deletions src/EFCore.Relational/Migrations/HistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ private IModel EnsureModel()
{
var conventionSet = Dependencies.ConventionSetBuilder.CreateConventionSet();

// Use public API to remove the convention, issue #214
ConventionSet.Remove(conventionSet.ModelInitializedConventions, typeof(DbSetFindingConvention));
ConventionSet.Remove(conventionSet.ModelInitializedConventions, typeof(RelationalDbFunctionAttributeConvention));
conventionSet.Remove(typeof(DbSetFindingConvention));
conventionSet.Remove(typeof(RelationalDbFunctionAttributeConvention));

var modelBuilder = new ModelBuilder(conventionSet);
modelBuilder.Entity<HistoryRow>(
Expand Down
Loading