From 614ed2a1b042b4c36a57aae2d397f04f7037d3fb Mon Sep 17 00:00:00 2001 From: Vladimir Kuznetsov Date: Tue, 8 Nov 2022 08:55:47 +0300 Subject: [PATCH] Add a generic overload of ConventionSetBuilder.Remove --- .../Metadata/Builders/ConventionSetBuilder.cs | 8 ++++++++ .../ModelBuilding/NonRelationshipTestBase.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/EFCore/Metadata/Builders/ConventionSetBuilder.cs b/src/EFCore/Metadata/Builders/ConventionSetBuilder.cs index 646503ac533..a79c5f41313 100644 --- a/src/EFCore/Metadata/Builders/ConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Builders/ConventionSetBuilder.cs @@ -65,6 +65,14 @@ public virtual void Add(Func conventionFactory) public virtual void Remove(Type conventionType) => _conventionSet.Remove(conventionType); + /// + /// Remove the convention of the given type. + /// + /// The type of convention to remove + public virtual void Remove() + where TImplementaion : IConvention + => Remove(typeof(TImplementaion)); + #region Hidden System.Object members /// diff --git a/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs b/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs index ab350ad9d5b..389a97806be 100644 --- a/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs @@ -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(); + }); + + var model = modelBuilder.FinalizeModel(); + Assert.Null(model["foo"]); }