Skip to content

Commit

Permalink
Add sugar methods to ConventionSet
Browse files Browse the repository at this point in the history
Part of #214
  • Loading branch information
AndriySvyryd committed Aug 5, 2022
1 parent 0821b27 commit 5f0c899
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 250 deletions.
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -57,80 +57,30 @@ protected RelationalConventionSetBuilder(
public override ConventionSet CreateConventionSet()
{
var conventionSet = base.CreateConventionSet();

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

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

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);

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));

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 TableSharingConcurrencyTokenConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalDbFunctionAttributeConvention(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.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
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.



// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.



// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions;

Expand Down
Loading

0 comments on commit 5f0c899

Please sign in to comment.