@@ -73,18 +73,24 @@ Namespace Migrations.Design
7373
7474 Using stringBuilder.Indent()
7575
76+ Dim enabled As Boolean
77+ Dim useOldBehavior = AppContext.TryGetSwitch( "Microsoft.EntityFrameworkCore.Issue23456" , enabled) AndAlso enabled
78+
7679 ' Temporary patch: specifically exclude some annotations which are known to produce identical Fluent API calls across different
7780 ' providers, generating them as raw annotations instead.
78- Dim ambiguousAnnotations =
79- RemoveAmbiguousFluentApiAnnotations(
80- annotations,
81- Function (name)
82- Return name.EndsWith( ":ValueGenerationStrategy" , StringComparison.Ordinal) _
83- OrElse name.EndsWith( ":IdentityIncrement" , StringComparison.Ordinal) _
84- OrElse name.EndsWith( ":IdentitySeed" , StringComparison.Ordinal) _
85- OrElse name.EndsWith( ":HiLoSequenceName" , StringComparison.Ordinal) _
86- OrElse name.EndsWith( ":HiLoSequenceSchema" , StringComparison.Ordinal)
87- End Function )
81+ Dim ambiguousAnnotations As IReadOnlyList( Of IAnnotation) = Array.Empty( Of IAnnotation)
82+ If Not useOldBehavior Then
83+ ambiguousAnnotations =
84+ RemoveAmbiguousFluentApiAnnotations(
85+ annotations,
86+ Function (name)
87+ Return name.EndsWith( ":ValueGenerationStrategy" , StringComparison.Ordinal) _
88+ OrElse name.EndsWith( ":IdentityIncrement" , StringComparison.Ordinal) _
89+ OrElse name.EndsWith( ":IdentitySeed" , StringComparison.Ordinal) _
90+ OrElse name.EndsWith( ":HiLoSequenceName" , StringComparison.Ordinal) _
91+ OrElse name.EndsWith( ":HiLoSequenceSchema" , StringComparison.Ordinal)
92+ End Function )
93+ End If
8894
8995 For Each methodCallCodeFragment In AnnotationCodeGenerator.GenerateFluentApiCalls(model, annotations)
9096 stringBuilder.AppendLines(VBCode.Fragment(methodCallCodeFragment, vertical:= True ), True )
@@ -136,21 +142,24 @@ Namespace Migrations.Design
136142 NotNull(entityTypes, NameOf (entityTypes))
137143 NotNull(stringBuilder, NameOf (stringBuilder))
138144
139- For Each entityType In entityTypes.Where( Function (e) e.FindOwnership() Is Nothing )
145+ For Each entityType In entityTypes.Where( Function (e) Not e.HasDefiningNavigation() AndAlso
146+ e.FindOwnership() Is Nothing )
140147 stringBuilder.AppendLine()
141148 GenerateEntityType(builderName, entityType, stringBuilder)
142149 Next
143150
144151 For Each entityType In entityTypes.Where(
145- Function (e) e.FindOwnership() Is Nothing AndAlso
152+ Function (e) Not e.HasDefiningNavigation() AndAlso
153+ e.FindOwnership() Is Nothing AndAlso
146154 (e.GetDeclaredForeignKeys().Any() OrElse e.GetDeclaredReferencingForeignKeys().Any( Function (fk) fk.IsOwnership)))
147155
148156 stringBuilder.AppendLine()
149157 GenerateEntityTypeRelationships(builderName, entityType, stringBuilder)
150158 Next
151159
152160 For Each entityType In entityTypes.Where(
153- Function (e) e.FindOwnership() Is Nothing AndAlso
161+ Function (e) Not e.HasDefiningNavigation() AndAlso
162+ e.FindOwnership() Is Nothing AndAlso
154163 e.GetDeclaredNavigations().Any( Function (n) Not n.IsOnDependent AndAlso Not n.ForeignKey.IsOwnership))
155164
156165 stringBuilder.AppendLine()
@@ -176,21 +185,10 @@ Namespace Migrations.Design
176185 Dim ownership = entityType.FindOwnership()
177186 Dim ownerNavigation = ownership?.PrincipalToDependent.Name
178187
179- Dim GetOwnedName = Function (Type As ITypeBase, simpleName As String , ownershipNavigation As String ) As String
180- Return Type.Name & "." & ownershipNavigation & "#" & simpleName
181- End Function
182-
183- Dim entityTypeName = entityType.Name
184- If ownerNavigation IsNot Nothing AndAlso
185- entityType.HasSharedClrType AndAlso
186- entityTypeName = GetOwnedName(ownership.PrincipalEntityType, entityType.ClrType.ShortDisplayName(), ownerNavigation) Then
187- entityTypeName = entityType.ClrType.DisplayName()
188- End If
189-
190188 stringBuilder.
191189 Append(builderName).
192190 Append( If (ownerNavigation IsNot Nothing , If (ownership.IsUnique, ".OwnsOne(" , ".OwnsMany(" ), ".Entity(" )).
193- Append(VBCode.Literal(entityTypeName ))
191+ Append(VBCode.Literal(entityType.Name ))
194192
195193 If ownerNavigation IsNot Nothing Then
196194 stringBuilder.
@@ -200,7 +198,7 @@ Namespace Migrations.Design
200198
201199 If builderName.StartsWith( "b" , StringComparison.Ordinal) Then
202200 Dim counter = 1
203- If builderName.Length > 1 AndAlso Integer .TryParse(builderName.Substring( 1 , builderName.Length - 1 ), counter) Then
201+ If builderName.Length > 1 AndAlso Integer .TryParse(builderName.Substring( 1 ), counter) Then
204202 counter += 1
205203 End If
206204
@@ -231,7 +229,10 @@ Namespace Migrations.Design
231229
232230 If ownerNavigation IsNot Nothing Then
233231 GenerateRelationships(builderName, entityType, stringBuilder)
234- GenerateNavigations(builderName, entityType.GetDeclaredNavigations().Where( Function (n) Not n.IsOnDependent AndAlso Not n.ForeignKey.IsOwnership), stringBuilder)
232+ GenerateNavigations(
233+ builderName, entityType.GetDeclaredNavigations().
234+ Where ( Function (n) Not n.IsOnDependent AndAlso
235+ Not n.ForeignKey.IsOwnership), stringBuilder)
235236 End If
236237
237238 GenerateData(builderName, entityType.GetProperties(), entityType.GetSeedData(providerValues:= True ), stringBuilder)
@@ -469,10 +470,10 @@ Namespace Migrations.Design
469470
470471 Dim firstProperty = True
471472 For Each [property] In properties
472- If Not firstProperty Then
473- stringBuilder.AppendLine()
474- Else
473+ If firstProperty Then
475474 firstProperty = False
475+ Else
476+ stringBuilder.AppendLine()
476477 End If
477478
478479 GenerateProperty(builderName, [property], stringBuilder)
@@ -497,12 +498,12 @@ Namespace Migrations.Design
497498 Dim clrType = If (FindValueConverter([property])?.ProviderClrType.MakeNullable([property].IsNullable), [property].ClrType)
498499
499500 stringBuilder.
500- Append(builderName).
501- Append( ".Property(Of " ).
502- Append(VBCode.Reference(clrType)).
503- Append( ")(" ).
504- Append(VBCode.Literal([property].Name)).
505- Append( ")" )
501+ Append(builderName).
502+ Append( ".Property(Of " ).
503+ Append(VBCode.Reference(clrType)).
504+ Append( ")(" ).
505+ Append(VBCode.Literal([property].Name)).
506+ Append( ")" )
506507
507508 Using stringBuilder.Indent()
508509 If [property].IsConcurrencyToken Then
@@ -577,18 +578,25 @@ Namespace Migrations.Design
577578 GenerateFluentApiForDefaultValue([property], stringBuilder)
578579 annotations.Remove(RelationalAnnotationNames.DefaultValue)
579580
581+ Dim enabled As Boolean
582+ Dim useOldBehavior = AppContext.TryGetSwitch( "Microsoft.EntityFrameworkCore.Issue23456" , enabled) AndAlso enabled
583+
580584 ' Temporary patch: specifically exclude some annotations which are known to produce identical Fluent API calls across different
581585 ' providers, generating them as raw annotations instead.
582- Dim ambiguousAnnotations = RemoveAmbiguousFluentApiAnnotations(
583- annotations,
584- Function (name)
585- Return name.EndsWith( ":ValueGenerationStrategy" , StringComparison.Ordinal) _
586- OrElse name.EndsWith( ":IdentityIncrement" , StringComparison.Ordinal) _
587- OrElse name.EndsWith( ":IdentitySeed" , StringComparison.Ordinal) _
588- OrElse name.EndsWith( ":HiLoSequenceName" , StringComparison.Ordinal) _
589- OrElse name.EndsWith( ":HiLoSequenceSchema" , StringComparison.Ordinal)
590- End Function
591- )
586+ Dim ambiguousAnnotations As IReadOnlyList( Of IAnnotation) = Array.Empty( Of IAnnotation)
587+
588+ If Not useOldBehavior Then
589+ ambiguousAnnotations = RemoveAmbiguousFluentApiAnnotations(
590+ annotations,
591+ Function (name)
592+ Return name.EndsWith( ":ValueGenerationStrategy" , StringComparison.Ordinal) _
593+ OrElse name.EndsWith( ":IdentityIncrement" , StringComparison.Ordinal) _
594+ OrElse name.EndsWith( ":IdentitySeed" , StringComparison.Ordinal) _
595+ OrElse name.EndsWith( ":HiLoSequenceName" , StringComparison.Ordinal) _
596+ OrElse name.EndsWith( ":HiLoSequenceSchema" , StringComparison.Ordinal)
597+ End Function
598+ )
599+ End If
592600
593601 For Each methodCallCodeFragment In AnnotationCodeGenerator.GenerateFluentApiCalls([property], annotations)
594602 stringBuilder.
@@ -764,15 +772,25 @@ Namespace Migrations.Design
764772 Protected Overridable Sub GenerateIndexAnnotations(index As IIndex,
765773 stringBuilder As IndentedStringBuilder)
766774
775+ NotNull(index, NameOf (index))
776+ NotNull(stringBuilder, NameOf (stringBuilder))
777+
767778 Dim annotations = AnnotationCodeGenerator.
768779 FilterIgnoredAnnotations(index.GetAnnotations()).
769780 ToDictionary( Function (a) a.Name, Function (a) a)
770781
782+ Dim enabled As Boolean
783+ Dim useOldBehavior = AppContext.TryGetSwitch( "Microsoft.EntityFrameworkCore.Issue23456" , enabled) AndAlso enabled
784+
771785 ' Temporary patch: specifically exclude some annotations which are known to produce identical Fluent API calls across different
772786 ' providers, generating them as raw annotations instead.
773- Dim ambiguousAnnotations = RemoveAmbiguousFluentApiAnnotations(
787+ Dim ambiguousAnnotations As IReadOnlyList( Of IAnnotation) = Array.Empty( Of IAnnotation)
788+
789+ If Not useOldBehavior Then
790+ ambiguousAnnotations = RemoveAmbiguousFluentApiAnnotations(
774791 annotations,
775792 Function (name) name.EndsWith( ":Include" , StringComparison.Ordinal))
793+ End If
776794
777795 For Each methodCallCodeFragment In AnnotationCodeGenerator.GenerateFluentApiCalls(index, annotations)
778796 stringBuilder.
@@ -841,7 +859,7 @@ Namespace Migrations.Design
841859 ' Issue #23173
842860 stringBuilder.Append( ", excludedFromMigrations:=true" )
843861 Else
844- stringBuilder.Append( ", Function (t) t.ExcludeFromMigrations()" )
862+ stringBuilder.Append( ", Sub (t) t.ExcludeFromMigrations()" )
845863 End If
846864 End If
847865
0 commit comments