@@ -70,29 +70,23 @@ public override IEnumerable<IAnnotation> For(ITable table, bool designTime)
70
70
{
71
71
yield break ;
72
72
}
73
- #if ! NET8_0
74
- var
9E12
span> entityType = table . EntityTypeMappings . First ( ) . EntityType ;
75
-
76
- if ( GetActualEntityTypeCharSet ( entityType ) is string charSet )
73
+ #if NET8_0
74
+ var entityType = table . EntityTypeMappings . First ( ) . TypeBase ;
75
+ if ( GetActualTypeBaseCharSet ( entityType ) is string charSet )
77
76
yield return new Annotation ( MySQLAnnotationNames . Charset , charSet ) ;
78
77
79
- if ( GetActualEntityTypeCollation ( entityType ) is string collation )
78
+ if ( GetActualTypeBaseCollation ( entityType ) is string collation )
80
79
yield return new Annotation ( RelationalAnnotationNames . Collation , collation ) ;
81
-
82
- foreach ( var annotation in entityType . GetAnnotations ( ) . Where ( a => a . Name is MySQLAnnotationNames . StoreOptions ) )
83
- yield return annotation ;
84
80
#else
85
- var typeBase = table . EntityTypeMappings . First ( ) . TypeBase ;
86
-
87
- if ( GetActualTypeBaseCharSet ( typeBase ) is string charSet )
81
+ var entityType = table . EntityTypeMappings . First ( ) . EntityType ;
82
+ if ( GetActualEntityTypeCharSet ( entityType ) is string charSet )
88
83
yield return new Annotation ( MySQLAnnotationNames . Charset , charSet ) ;
89
84
90
- if ( GetActualTypeBaseCollation ( typeBase ) is string collation )
85
+ if ( GetActualEntityTypeCollation ( entityType ) is string collation )
91
86
yield return new Annotation ( RelationalAnnotationNames . Collation , collation ) ;
92
-
93
- foreach ( var annotation in typeBase . GetAnnotations ( ) . Where ( a => a . Name is MySQLAnnotationNames . StoreOptions ) )
94
- yield return annotation ;
95
87
#endif
88
+ foreach ( var annotation in entityType . GetAnnotations ( ) . Where ( a => a . Name is MySQLAnnotationNames . StoreOptions ) )
89
+ yield return annotation ;
96
90
}
97
91
98
92
public override IEnumerable < IAnnotation > For ( IUniqueConstraint constraint , bool designTime )
@@ -131,57 +125,32 @@ public override IEnumerable<IAnnotation> For(ITableIndex index, bool designTime)
131
125
yield return new Annotation ( MySQLAnnotationNames . SpatialIndex , isSpatial . Value ) ;
132
126
}
133
127
134
- #if NET6_0
135
128
public override IEnumerable < IAnnotation > For ( IColumn column , bool designTime )
136
129
{
137
130
if ( ! designTime )
138
131
yield break ;
139
132
140
133
var table = StoreObjectIdentifier . Table ( column . Table . Name , column . Table . Schema ) ;
141
134
var properties = column . PropertyMappings . Select ( m => m . Property ) . ToArray ( ) ;
142
-
143
- if ( column . PropertyMappings . Where (
144
- m => m . TableMapping . IsSharedTablePrincipal && m . TableMapping . EntityType == m . Property . DeclaringEntityType )
145
- . Select ( m => m . Property )
146
- . FirstOrDefault ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . IdentityColumn ) is IProperty identityProperty )
147
- {
148
- var valueGenerationStrategy = identityProperty . GetValueGenerationStrategy ( table ) ;
149
- yield return new Annotation ( MySQLAnnotationNames . ValueGenerationStrategy , valueGenerationStrategy ) ;
150
- }
151
- else if ( properties . FirstOrDefault
152
- ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . ComputedColumn ) is IProperty computedProperty )
153
- {
154
- var valueGenerationStrategy = computedProperty . GetValueGenerationStrategy ( table ) ;
155
- yield return new Annotation ( MySQLAnnotationNames . ValueGenerationStrategy , valueGenerationStrategy ) ;
156
- }
157
- }
158
- #elif NET8_0
159
-
160
- public override IEnumerable < IAnnotation > For ( IColumn column , bool designTime<
10000
/span>)
161
- {
162
- if ( ! designTime )
163
- yield break ;
164
-
165
- var table = StoreObjectIdentifier . Table ( column . Table . Name , column . Table . Schema ) ;
166
- var properties = column . PropertyMappings . Select ( m => m . Property ) . ToArray ( ) ;
167
-
168
- if ( column . PropertyMappings . Where ( m => m . TableMapping . IsSharedTablePrincipal ?? true
169
- && m . TableMapping . TypeBase == m . Property . DeclaringEntityType )
170
- . Select ( m => m . Property )
171
- . FirstOrDefault ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . IdentityColumn ) is IProperty identityProperty )
135
+ #if NET8_0
136
+ if ( column . PropertyMappings . Where ( m => m . TableMapping . IsSharedTablePrincipal ?? true && m . TableMapping . TypeBase == m . Property . DeclaringType )
137
+ . Select ( m => m . Property )
138
+ . FirstOrDefault ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . IdentityColumn ) is IProperty identityProperty )
139
+ #else
140
+ if ( column . PropertyMappings . Where ( m => m . TableMapping . IsSharedTablePrincipal && m . TableMapping . EntityType == m . Property . DeclaringEntityType )
141
+ . Select ( m => m . Property )
142
+ . FirstOrDefault ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . IdentityColumn ) is IProperty identityProperty )
143
+ #endif
172
144
{
173
145
var valueGenerationStrategy = identityProperty . GetValueGenerationStrategy ( table ) ;
174
146
yield return new Annotation ( MySQLAnnotationNames . ValueGenerationStrategy , valueGenerationStrategy ) ;
175
147
}
176
- else if ( properties . FirstOrDefault
177
- ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . ComputedColumn ) is IProperty computedProperty )
148
+ else if ( properties . FirstOrDefault ( p => p . GetValueGenerationStrategy ( table ) == MySQLValueGenerationStrategy . ComputedColumn ) is IProperty computedProperty )
178
149
{
179
150
var valueGenerationStrategy = computedProperty . GetValueGenerationStrategy ( table ) ;
180
151
yield return new Annotation ( MySQLAnnotationNames . ValueGenerationStrategy , valueGenerationStrategy ) ;
181
152
}
182
153
}
183
- #endif
184
-
185
154
186
155
protected virtual string GetActualModelCharSet ( IModel model )
187
156
{
@@ -193,148 +162,138 @@ protected virtual string GetActualModelCollation(IModel model)
193
162
return model . GetCollation ( ) ! ;
194
163
}
195
164
196
-
197
- #if ! NET8_0
198
- protected virtual string ? GetActualEntityTypeCharSet ( IEntityType entityType )
165
+ #if NET8_0
166
+ protected virtual string ? GetActualTypeBaseCharSet ( ITypeBase typeBase )
199
167
{
200
- var entityTypeCharSet = entityType . GetCharSet ( ) ;
168
+ var typeBaseCharSet = typeBase . GetCharSet ( ) ;
201
169
202
- if ( entityTypeCharSet is not null )
203
- return entityTypeCharSet ;
170
+ if ( typeBaseCharSet is not null )
171
+ return typeBaseCharSet ;
204
172
205
- if ( entityTypeCharSet is null )
173
+ if ( typeBaseCharSet is null )
206
174
{
207
- var entityTypeCollation = entityType . GetCollation ( ) ;
208
- var actualModelCharSet = GetActualModelCharSet ( entityType . Model ) ;
175
+ var typeBaseCollation = typeBase . GetCollation ( ) ;
176
+ var actualModelCharSet = GetActualModelCharSet ( typeBase . Model ) ;
209
177
210
- if ( entityTypeCollation is not null )
178
+ if ( typeBaseCollation is not null )
211
179
{
212
- return actualModelCharSet is not null && entityTypeCollation . StartsWith ( actualModelCharSet , StringComparison . OrdinalIgnoreCase )
180
+ return actualModelCharSet is not null && typeBaseCollation . StartsWith ( actualModelCharSet , StringComparison . OrdinalIgnoreCase )
213
181
? actualModelCharSet : null ;
214
182
}
215
183
216
- var actualModelCollation = GetActualModelCollation ( entityType . Model ) ;
184
+ var actualModelCollation = GetActualModelCollation ( typeBase . Model ) ;
217
185
218
186
if ( actualModelCollation is not null )
219
187
{
220
188
return actualModelCharSet is not null && actualModelCollation . StartsWith ( actualModelCharSet , StringComparison . OrdinalIgnoreCase )
221
189
? actualModelCharSet : null ;
222
190
}
223
-
224
191
return actualModelCharSet ;
225
192
}
226
-
227
193
return null ;
228
194
}
229
195
230
- protected virtual string ? GetActualEntityTypeCollation ( IEntityType entityType )
196
+ protected virtual string ? GetActualTypeBaseCollation ( ITypeBase typeBase )
231
197
{
232
- var entityTypeCollation = entityType . GetCollation ( ) ;
198
+ var typeBaseCollation = typeBase . GetCollation ( ) ;
233
199
234
- if ( entityTypeCollation is not null )
235
- return entityTypeCollation ;
200
+ if ( typeBaseCollation is not null )
201
+ return typeBaseCollation ;
236
202
237
- if ( entityTypeCollation is null )
203
+ if ( typeBaseCollation is null )
238
204
{
239
- var entityTypeCharSet = entityType . GetCharSet ( ) ;
240
- var actualModelCollation = GetActualModelCollation ( entityType . Model ) ;
205
+ var typeBaseCharSet = typeBase . GetCharSet ( ) ;
206
+ var actualModelCollation = GetActualModelCollation ( typeBase . Model ) ;
241
207
242
- if ( entityTypeCharSet is not null )
208
+ if ( typeBaseCharSet is not null )
243
209
{
244
- return actualModelCollation is not null && actualModelCollation . StartsWith ( entityTypeCharSet , StringComparison . OrdinalIgnoreCase )
210
+ return actualModelCollation is not null && actualModelCollation . StartsWith ( typeBaseCharSet , StringComparison . OrdinalIgnoreCase )
245
211
? actualModelCollation : null ;
246
212
}
247
-
248
213
return actualModelCollation ;
249
214
}
250
-
251
215
return null ;
252
216
}
253
-
254
- protected virtual string ? GetActualPropertyCharSet ( IProperty [ ] properties )
255
- {
256
- return properties . Select ( p => p . GetCharSet ( ) ) . FirstOrDefault ( s => s is not null ) ??
257
- properties . Select (
258
- p => p . FindTypeMapping ( ) is MySQLStringTypeMapping
259
- ? GetActualEntityTypeCharSet ( p . DeclaringEntityType ) is string charSet &&
260
- ( p . GetCollation ( ) is not string collation ||
261
- collation . StartsWith ( charSet , StringComparison . OrdinalIgnoreCase ) )
262
- ? charSet
263
- : null
264
- : null )
265
- . FirstOrDefault ( s => s is not null ) ;
266
- }
267
217
#else
268
- protected virtual string ? GetActualTypeBaseCharSet ( ITypeBase typeBase )
218
+ protected virtual string ? GetActualEntityTypeCharSet ( IEntityType entityType )
269
219
{
270
- var typeBaseCharSet = typeBase . GetCharSet ( ) ;
220
+ var entityTypeCharSet = entityType . GetCharSet ( ) ;
271
221
272
- if ( typeBaseCharSet is not null )
273
- return typeBaseCharSet ;
222
+ if ( entityTypeCharSet is not null )
223
+ return entityTypeCharSet ;
274
224
275
- if ( typeBaseCharSet is null )
225
+ if ( entityTypeCharSet is null )
276
226
{
277
- var typeBaseCollation = typeBase . GetCollation ( ) ;
278
- var actualModelCharSet = GetActualModelCharSet ( typeBase . Model ) ;
227
+ var entityTypeCollation = entityType . GetCollation ( ) ;
228
+ var actualModelCharSet = GetActualModelCharSet ( entityType . Model ) ;
279
229
280
- if ( typeBaseCollation is not null )
230
+ if ( entityTypeCollation is not null )
281
231
{
282
- return actualModelCharSet is not null && typeBaseCollation . StartsWith ( actualModelCharSet , StringComparison . OrdinalIgnoreCase )
232
+ return actualModelCharSet is not null && entityTypeCollation . StartsWith ( actualModelCharSet , StringComparison . OrdinalIgnoreCase )
283
233
? actualModelCharSet : null ;
284
234
}
285
235
286
- var actualModelCollation = GetActualModelCollation ( typeBase . Model ) ;
236
+ var actualModelCollation = GetActualModelCollation ( entityType . Model ) ;
287
237
288
238
if ( actualModelCollation is not null )
289
239
{
290
240
return actualModelCharSet is not null && actualModelCollation . StartsWith ( actualModelCharSet , StringComparison . OrdinalIgnoreCase )
291
241
? actualModelCharSet : null ;
292
242
}
293
-
294
243
return actualModelCharSet ;
295
244
}
296
-
297
245
return null ;
298
246
}
299
247
300
- protected virtual string ? GetActualTypeBaseCollation ( ITypeBase typeBase )
248
+ protected virtual string ? GetActualEntityTypeCollation ( IEntityType entityType )
301
249
{
302
- var typeBaseCollation = typeBase . GetCollation ( ) ;
250
+ var entityTypeCollation = entityType . GetCollation ( ) ;
303
251
304
- if ( typeBaseCollation is not null )
305
- return typeBaseCollation ;
252
+ if ( entityTypeCollation is not null )
253
+ return entityTypeCollation ;
306
254
307
- if ( typeBaseCollation is null )
255
+ if ( entityTypeCollation is null )
308
256
{
309
- var typeBaseCharSet = typeBase . GetCharSet ( ) ;
310
- var actualModelCollation = GetActualModelCollation ( typeBase . Model ) ;
257
+ var entityTypeCharSet = entityType . GetCharSet ( ) ;
258
+ var actualModelCollation = GetActualModelCollation ( entityType . Model ) ;
311
259
312
- if ( typeBaseCharSet is not null )
260
+ if ( entityTypeCharSet is not null )
313
261
{
314
- return actualModelCollation is not null && actualModelCollation . StartsWith ( typeBaseCharSet , StringComparison . OrdinalIgnoreCase )
262
+ return actualModelCollation is not null && actualModelCollation . StartsWith ( entityTypeCharSet , StringComparison . OrdinalIgnoreCase )
315
263
? actualModelCollation : null ;
316
264
}
317
-
318
265
return actualModelCollation ;
319
266
}
320
-
321
267
return null ;
322
268
}
269
+ #endif
323
270
324
271
protected virtual string ? GetActualPropertyCharSet ( IProperty [ ] properties )
325
272
{
273
+ #if NET8_0
274
+ return properties . Select ( p => p . GetCharSet ( ) ) . FirstOrDefault ( s => s is not null ) ??
275
+ properties . Select (
276
+ p => p . FindTypeMapping ( ) is MySQLStringTypeMapping
277
+ ? GetActualTypeBaseCharSet ( p . DeclaringType ) is string charSet &&
278
+ ( p . GetCollation ( ) is not string collation ||
279
+ collation . StartsWith ( charSet , StringComparison . OrdinalIgnoreCase ) )
280
+ ? charSet
281
+ : null
282
+ : null )
283
+ . FirstOrDefault ( s => s is not null ) ;
284
+ }
285
+ #else
326
286
return properties . Select ( p => p . GetCharSet ( ) ) . FirstOrDefault ( s => s is not null ) ??
327
287
properties . Select (
328
- p => p . FindTypeMapping ( ) is MySQLStringTypeMapping
329
- ? GetActualTypeBaseCharSet ( p . DeclaringType ) is string charSet &&
330
- ( p . GetCollation ( ) is not string collation ||
331
- collation . StartsWith ( charSet , StringComparison . OrdinalIgnoreCase ) )
332
- ? charSet
333
- : null
334
- : null )
288
+ p => p . FindTypeMapping ( ) is MySQLStringTypeMapping
289
+ ? GetActualEntityTypeCharSet ( p . DeclaringEntityType ) is string charSet &&
290
+ ( p . GetCollation ( ) is not string collation ||
291
+ collation . StartsWith ( charSet , StringComparison . OrdinalIgnoreCase ) )
292
+ ? charSet
293
+ : null
294
+ : null )
335
295
. FirstOrDefault ( s => s is not null ) ;
336
296
}
337
297
#endif
338
-
339
298
}
340
299
}
0 commit comments