From 52297c65cbead89023fc9e0c41c3f498bc6ad4bc Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 21 Jul 2020 23:56:39 +0300 Subject: [PATCH] Stop scaffolding IsTableExcludedFromMigrations Fixes #21470 --- .../Design/AnnotationCodeGenerator.cs | 6 +++- .../Design/AnnotationCodeGeneratorTest.cs | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/EFCore.Relational.Tests/Design/AnnotationCodeGeneratorTest.cs diff --git a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs index 5310643286b..64964d6878b 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs @@ -80,7 +80,11 @@ public virtual void RemoveAnnotationsHandledByConventions(IModel model, IDiction /// public virtual void RemoveAnnotationsHandledByConventions( IEntityType entityType, IDictionary annotations) - => RemoveConventionalAnnotationsHelper(entityType, annotations, IsHandledByConvention); + { + annotations.Remove(RelationalAnnotationNames.IsTableExcludedFromMigrations); + + RemoveConventionalAnnotationsHelper(entityType, annotations, IsHandledByConvention); + } /// public virtual void RemoveAnnotationsHandledByConventions( diff --git a/test/EFCore.Relational.Tests/Design/AnnotationCodeGeneratorTest.cs b/test/EFCore.Relational.Tests/Design/AnnotationCodeGeneratorTest.cs new file mode 100644 index 00000000000..3952fb64d09 --- /dev/null +++ b/test/EFCore.Relational.Tests/Design/AnnotationCodeGeneratorTest.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace Microsoft.EntityFrameworkCore.Design +{ + public class AnnotationCodeGeneratorTest + { + [ConditionalFact] + public void IsTableExcludedFromMigrations_false_is_handled_by_convention() + { + var modelBuilder = CreateModelBuilder(); + modelBuilder.Entity("foo").ToTable("foo"); + var entityType = modelBuilder.Model.GetEntityTypes().Single(); + + var annotations = entityType.GetAnnotations().ToDictionary(a => a.Name, a => a); + CreateGenerator().RemoveAnnotationsHandledByConventions(entityType, annotations); + + Assert.DoesNotContain(RelationalAnnotationNames.IsTableExcludedFromMigrations, annotations.Keys); + } + + private ModelBuilder CreateModelBuilder() => RelationalTestHelpers.Instance.CreateConventionBuilder(); + + private AnnotationCodeGenerator CreateGenerator() => new AnnotationCodeGenerator( + new AnnotationCodeGeneratorDependencies( + new TestRelationalTypeMappingSource( + TestServiceFactory.Instance.Create(), + TestServiceFactory.Instance.Create()))); + } +}