|
4 | 4 | // ReSharper disable once CheckNamespace |
5 | 5 |
|
6 | 6 | using Microsoft.EntityFrameworkCore.Internal; |
| 7 | +using Microsoft.EntityFrameworkCore.Metadata.Internal; |
7 | 8 |
|
8 | 9 | namespace Microsoft.EntityFrameworkCore; |
9 | 10 |
|
@@ -370,20 +371,87 @@ public static bool IsMappedToJson(this IReadOnlyTypeBase typeBase) |
370 | 371 | /// <param name="typeBase">The type to get the container column name for.</param> |
371 | 372 | /// <returns>The container column name to which the type is mapped.</returns> |
372 | 373 | public static string? GetContainerColumnName(this IReadOnlyTypeBase typeBase) |
373 | | - => typeBase is IReadOnlyEntityType entityType |
374 | | - ? entityType.GetContainerColumnName() |
375 | | - : ((IReadOnlyComplexType)typeBase).GetContainerColumnName(); |
| 374 | + { |
| 375 | + var containerColumnName = typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnName); |
| 376 | + return containerColumnName != null |
| 377 | + ? (string?)containerColumnName.Value |
| 378 | + : typeBase is IReadOnlyEntityType entityType |
| 379 | + ? entityType.FindOwnership()?.PrincipalEntityType.GetContainerColumnName() |
| 380 | + : ((IReadOnlyComplexType)typeBase).ComplexProperty.DeclaringType.GetContainerColumnName(); |
| 381 | + } |
| 382 | + |
| 383 | + /// <summary> |
| 384 | + /// Sets the name of the container column to which the type is mapped. |
| 385 | + /// </summary> |
| 386 | + /// <param name="typeBase">The type to set the container column name for.</param> |
| 387 | + /// <param name="columnName">The name to set.</param> |
| 388 | + public static void SetContainerColumnName(this IMutableTypeBase typeBase, string? columnName) |
| 389 | + => typeBase.SetOrRemoveAnnotation(RelationalAnnotationNames.ContainerColumnName, columnName); |
| 390 | + |
| 391 | + /// <summary> |
| 392 | + /// Sets the name of the container column to which the type is mapped. |
| 393 | + /// </summary> |
| 394 | + /// <param name="typeBase">The type to set the container column name for.</param> |
| 395 | + /// <param name="columnName">The name to set.</param> |
| 396 | + /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> |
| 397 | + /// <returns>The configured value.</returns> |
| 398 | + public static string? SetContainerColumnName( |
| 399 | + this IConventionTypeBase typeBase, |
| 400 | + string? columnName, |
| 401 | + bool fromDataAnnotation = false) |
| 402 | + => (string?)typeBase.SetAnnotation(RelationalAnnotationNames.ContainerColumnName, columnName, fromDataAnnotation)?.Value; |
| 403 | + |
| 404 | + /// <summary> |
| 405 | + /// Gets the <see cref="ConfigurationSource" /> for the container column name. |
| 406 | + /// </summary> |
| 407 | + /// <param name="typeBase">The type to get the container column name configuration source for.</param> |
| 408 | + /// <returns>The <see cref="ConfigurationSource" /> for the container column name.</returns> |
| 409 | + public static ConfigurationSource? GetContainerColumnNameConfigurationSource(this IConventionTypeBase typeBase) |
| 410 | + => typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnName) |
| 411 | + ?.GetConfigurationSource(); |
376 | 412 |
|
377 | 413 | /// <summary> |
378 | 414 | /// Gets the column type to use for the container column to which the type is mapped. |
379 | 415 | /// </summary> |
380 | 416 | /// <param name="typeBase">The type.</param> |
381 | 417 | /// <returns>The database column type.</returns> |
382 | 418 | public static string? GetContainerColumnType(this IReadOnlyTypeBase typeBase) |
383 | | - => typeBase is IReadOnlyEntityType entityType |
384 | | - ? entityType.GetContainerColumnType() |
385 | | - : null; |
| 419 | + => typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value is string columnName |
| 420 | + ? columnName |
| 421 | + : typeBase is IReadOnlyEntityType entityType |
| 422 | + ? entityType.FindOwnership()?.PrincipalEntityType.GetContainerColumnType() |
| 423 | + : ((IReadOnlyComplexType)typeBase).ComplexProperty.DeclaringType.GetContainerColumnType(); |
| 424 | + |
| 425 | + /// <summary> |
| 426 | + /// Sets the type of the container column to which the type is mapped. |
| 427 | + /// </summary> |
| 428 | + /// <param name="typeBase">The type to set the container column type for.</param> |
| 429 | + /// <param name="columnType">The type to set.</param> |
| 430 | + public static void SetContainerColumnType(this IMutableTypeBase typeBase, string? columnType) |
| 431 | + => typeBase.SetOrRemoveAnnotation(RelationalAnnotationNames.ContainerColumnType, columnType); |
386 | 432 |
|
| 433 | + /// <summary> |
| 434 | + /// Sets the type of the container column to which the type is mapped. |
| 435 | + /// </summary> |
| 436 | + /// <param name="typeBase">The type to set the container column type for.</param> |
| 437 | + /// <param name="columnType">The type to set.</param> |
| 438 | + /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> |
| 439 | + /// <returns>The configured value.</returns> |
| 440 | + public static string? SetContainerColumnType( |
| 441 | + this IConventionTypeBase typeBase, |
| 442 | + string? columnType, |
| 443 | + bool fromDataAnnotation = false) |
| 444 | + => (string?)typeBase.SetAnnotation(RelationalAnnotationNames.ContainerColumnType, columnType, fromDataAnnotation)?.Value; |
| 445 | + |
| 446 | + /// <summary> |
| 447 | + /// Gets the <see cref="ConfigurationSource" /> for the container column type. |
| 448 | + /// </summary> |
| 449 | + /// <param name="typeBase">The type to get the container column type configuration source for.</param> |
| 450 | + /// <returns>The <see cref="ConfigurationSource" /> for the container column type.</returns> |
| 451 | + public static ConfigurationSource? GetContainerColumnTypeConfigurationSource(this IConventionTypeBase typeBase) |
| 452 | + => typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnType) |
| 453 | + ?.GetConfigurationSource(); |
| 454 | + |
387 | 455 | /// <summary> |
388 | 456 | /// Gets the value of JSON property name used for the given entity mapped to a JSON column. |
389 | 457 | /// </summary> |
|
0 commit comments