Skip to content

Commit

Permalink
Add a generic overload of ConventionSetBuilder.Remove
Browse files Browse the repository at this point in the history
Fixes #29476
  • Loading branch information
kuznetsovvj authored Nov 8, 2022
1 parent a23cff5 commit fa33742
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/EFCore/Metadata/Builders/ConventionSetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public virtual void Add(Func<IServiceProvider, IConvention> conventionFactory)
public virtual void Remove(Type conventionType)
=> _conventionSet.Remove(conventionType);

/// <summary>
/// Remove the convention of the given type.
/// </summary>
/// <typeparam name="TImplementaion">The type of convention to remove</typeparam>
public virtual void Remove<TImplementaion>()
where TImplementaion : IConvention
=> Remove(typeof(TImplementaion));

#region Hidden System.Object members

/// <summary>
Expand Down
15 changes: 15 additions & 0 deletions test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,21 @@ public virtual void Conventions_can_be_removed()

var model = modelBuilder.FinalizeModel();

Assert.Null(model["foo"]);
}

[ConditionalFact]
public virtual void Conventions_can_be_removed_by_generic_method()
{
var modelBuilder = CreateModelBuilder(
c =>
{
c.Conventions.Add(s => new TestConvention());
c.Conventions.Remove<TestConvention>();
});

var model = modelBuilder.FinalizeModel();

Assert.Null(model["foo"]);
}

Expand Down

0 comments on commit fa33742

Please sign in to comment.