@@ -73,18 +73,24 @@ Namespace Migrations.Design
73
73
74
74
Using stringBuilder.Indent()
75
75
76
+ Dim enabled As Boolean
77
+ Dim useOldBehavior = AppContext.TryGetSwitch( "Microsoft.EntityFrameworkCore.Issue23456" , enabled) AndAlso enabled
78
+
76
79
' Temporary patch: specifically exclude some annotations which are known to produce identical Fluent API calls across different
77
80
' 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
88
94
89
95
For Each methodCallCodeFragment In AnnotationCodeGenerator.GenerateFluentApiCalls(model, annotations)
90
96
stringBuilder.AppendLines(VBCode.Fragment(methodCallCodeFragment, vertical:= True ), True )
@@ -136,21 +142,24 @@ Namespace Migrations.Design
136
142
NotNull(entityTypes, NameOf (entityTypes))
137
143
NotNull(stringBuilder, NameOf (stringBuilder))
138
144
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 )
140
147
stringBuilder.AppendLine()
141
148
GenerateEntityType(builderName, entityType, stringBuilder)
142
149
Next
143
150
144
151
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
146
154
(e.GetDeclaredForeignKeys().Any() OrElse e.GetDeclaredReferencingForeignKeys().Any( Function (fk) fk.IsOwnership)))
147
155
148
156
stringBuilder.AppendLine()
149
157
GenerateEntityTypeRelationships(builderName, entityType, stringBuilder)
150
158
Next
151
159
152
160
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
154
163
e.GetDeclaredNavigations().Any( Function (n) Not n.IsOnDependent AndAlso Not n.ForeignKey.IsOwnership))
155
164
156
165
stringBuilder.AppendLine()
@@ -176,21 +185,10 @@ Namespace Migrations.Design
176
185
Dim ownership = entityType.FindOwnership()
177
186
Dim ownerNavigation = ownership?.PrincipalToDependent.Name
178
187
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
-
190
188
stringBuilder.
191
189
Append(builderName).
192
190
Append( If (ownerNavigation IsNot Nothing , If (ownership.IsUnique, ".OwnsOne(" , ".OwnsMany(" ), ".Entity(" )).
193
- Append(VBCode.Literal(entityTypeName ))
191
+ Append(VBCode.Literal(entityType.Name ))
194
192
195
193
If ownerNavigation IsNot Nothing Then
196
194
stringBuilder.
@@ -200,7 +198,7 @@ Namespace Migrations.Design
200
198
201
199
If builderName.StartsWith( "b" , StringComparison.Ordinal) Then
202
200
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
204
202
counter += 1
205
203
End If
206
204
@@ -231,7 +229,10 @@ Namespace Migrations.Design
231
229
232
230
If ownerNavigation IsNot Nothing Then
233
231
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)
235
236
End If
236
237
237
238
GenerateData(builderName, entityType.GetProperties(), entityType.GetSeedData(providerValues:= True ), stringBuilder)
@@ -469,10 +470,10 @@ Namespace Migrations.Design
469
470
470
471
Dim firstProperty = True
471
472
For Each [property] In properties
472
- If Not firstProperty Then
473
- stringBuilder.AppendLine()
474
- Else
473
+ If firstProperty Then
475
474
firstProperty = False
475
+ Else
476
+ stringBuilder.AppendLine()
476
477
End If
477
478
478
479
GenerateProperty(builderName, [property], stringBuilder)
@@ -497,12 +498,12 @@ Namespace Migrations.Design
497
498
Dim clrType = If (FindValueConverter([property])?.ProviderClrType.MakeNullable([property].IsNullable), [property].ClrType)
498
499
499
500
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( ")" )
506
507
507
508
Using stringBuilder.Indent()
508
509
If [property].IsConcurrencyToken Then
@@ -577,18 +578,25 @@ Namespace Migrations.Design
577
578
GenerateFluentApiForDefaultValue([property], stringBuilder)
578
579
annotations.Remove(RelationalAnnotationNames.DefaultValue)
579
580
581
+ Dim enabled As Boolean
582
+ Dim useOldBehavior = AppContext.TryGetSwitch( "Microsoft.EntityFrameworkCore.Issue23456" , enabled) AndAlso enabled
583
+
580
584
' Temporary patch: specifically exclude some annotations which are known to produce identical Fluent API calls across different
581
585
' 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
592
600
593
601
For Each methodCallCodeFragment In AnnotationCodeGenerator.GenerateFluentApiCalls([property], annotations)
594
602
stringBuilder.
@@ -764,15 +772,25 @@ Namespace Migrations.Design
764
772
Protected Overridable Sub GenerateIndexAnnotations(index As IIndex,
765
773
stringBuilder As IndentedStringBuilder)
766
774
775
+ NotNull(index, NameOf (index))
776
+ NotNull(stringBuilder, NameOf (stringBuilder))
777
+
767
778
Dim annotations = AnnotationCodeGenerator.
768
779
FilterIgnoredAnnotations(index.GetAnnotations()).
769
780
ToDictionary( Function (a) a.Name, Function (a) a)
770
781
782
+ Dim enabled As Boolean
783
+ Dim useOldBehavior = AppContext.TryGetSwitch( "Microsoft.EntityFrameworkCore.Issue23456" , enabled) AndAlso enabled
784
+
771
785
' Temporary patch: specifically exclude some annotations which are known to produce identical Fluent API calls across different
772
786
' 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(
774
791
annotations,
775
792
Function (name) name.EndsWith( ":Include" , StringComparison.Ordinal))
793
+ End If
776
794
777
795
For Each methodCallCodeFragment In AnnotationCodeGenerator.GenerateFluentApiCalls(index, annotations)
778
796
stringBuilder.
@@ -841,7 +859,7 @@ Namespace Migrations.Design
841
859
' Issue #23173
842
860
stringBuilder.Append( ", excludedFromMigrations:=true" )
843
861
Else
844
- stringBuilder.Append( ", Function (t) t.ExcludeFromMigrations()" )
862
+ stringBuilder.Append( ", Sub (t) t.ExcludeFromMigrations()" )
845
863
End If
846
864
End If
847
865
0 commit comments