-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata work for json. Separated from main PR to make the review eas…
…ier. This PR includes: - builder methods, - conventions, - relational model, - model validation, - migrations, - update
- Loading branch information
Showing
50 changed files
with
4,251 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/EFCore.Relational/Extensions/Internal/RelationalPropertyInternalExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Internal | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public static class RelationalPropertyInternalExtensions | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public static bool IsOrdinalKeyProperty(this IReadOnlyProperty property) | ||
=> property.FindContainingPrimaryKey() is IReadOnlyKey key | ||
&& key.Properties.Count > 1 | ||
&& !property.IsForeignKey() | ||
&& property.IsShadowProperty() | ||
&& property.ClrType == typeof(int) | ||
&& property.GetJsonPropertyName() == null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/EFCore.Relational/Extensions/RelationalNavigationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
/// <summary> | ||
/// Relational database specific extension methods for <see cref="NavigationBuilder" />. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples. | ||
/// </remarks> | ||
public static class RelationalNavigationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the navigation of an entity mapped to a JSON column, mapping the navigation to a specific JSON property, | ||
/// rather than using the navigation name. | ||
/// </summary> | ||
/// <param name="navigationBuilder">The builder for the navigation being configured.</param> | ||
/// <param name="name">JSON property name to be used.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns> | ||
/// The same builder instance if the configuration was applied, | ||
/// <see langword="null" /> otherwise. | ||
/// </returns> | ||
public static IConventionNavigationBuilder? HasJsonPropertyName( | ||
this IConventionNavigationBuilder navigationBuilder, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
{ | ||
if (!navigationBuilder.CanSetJsonPropertyName(name, fromDataAnnotation)) | ||
{ | ||
return null; | ||
} | ||
|
||
navigationBuilder.Metadata.SetJsonPropertyName(name, fromDataAnnotation); | ||
|
||
return navigationBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Returns a value indicating whether the given value can be used as a JSON property name for a given navigation. | ||
/// </summary> | ||
/// <param name="navigationBuilder">The builder for the navigation being configured.</param> | ||
/// <param name="name">JSON property name to be used.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns><see langword="true" /> if the given value can be set as JSON property name for this navigation.</returns> | ||
public static bool CanSetJsonPropertyName( | ||
this IConventionNavigationBuilder navigationBuilder, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
=> navigationBuilder.CanSetAnnotation(RelationalAnnotationNames.JsonPropertyName, name, fromDataAnnotation); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/EFCore.Relational/Extensions/RelationalNavigationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
/// <summary> | ||
/// Navigation extension methods for relational database metadata. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples. | ||
/// </remarks> | ||
public static class RelationalNavigationExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the value of JSON property name used for the given navigation of an entity mapped to a JSON column. | ||
/// </summary> | ||
/// <remarks> | ||
/// Unless configured explicitly, navigation name is used. | ||
/// </remarks> | ||
/// <param name="navigation">The navigation.</param> | ||
/// <returns> | ||
/// The value for the JSON property used to store the value of this navigation. | ||
/// <see langword="null" /> is returned for navigations of entities that are not mapped to a JSON column. | ||
/// </returns> | ||
public static string? GetJsonPropertyName(this IReadOnlyNavigationBase navigation) | ||
=> (string?)navigation.FindAnnotation(RelationalAnnotationNames.JsonPropertyName)?.Value | ||
?? (!navigation.DeclaringEntityType.IsMappedToJson() ? null : navigation.Name); | ||
|
||
/// <summary> | ||
/// Sets the value of JSON property name used for the given navigation of an entity mapped to a JSON column. | ||
/// </summary> | ||
/// <param name="navigation">The navigation.</param> | ||
/// <param name="name">The name to be used.</param> | ||
public static void SetJsonPropertyName(this IMutableNavigationBase navigation, string? name) | ||
=> navigation.SetOrRemoveAnnotation( | ||
RelationalAnnotationNames.JsonPropertyName, | ||
Check.NullButNotEmpty(name, nameof(name))); | ||
|
||
/// <summary> | ||
/// Sets the value of JSON property name used for the given navigation of an entity mapped to a JSON column. | ||
/// </summary> | ||
/// <param name="navigation">The navigation.</param> | ||
/// <param name="name">The name to be used.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns>The configured value.</returns> | ||
public static string? SetJsonPropertyName( | ||
this IConventionNavigationBase navigation, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
{ | ||
navigation.SetOrRemoveAnnotation( | ||
RelationalAnnotationNames.JsonPropertyName, | ||
Check.NullButNotEmpty(name, nameof(name)), | ||
fromDataAnnotation); | ||
|
||
return name; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ConfigurationSource" /> for the JSON property name for a given navigation. | ||
/// </summary> | ||
/// <param name="navigation">The navigation.</param> | ||
/// <returns>The <see cref="ConfigurationSource" /> for the JSON property name for a given navigation.</returns> | ||
public static ConfigurationSource? GetJsonPropertyNameConfigurationSource(this IConventionNavigationBase navigation) | ||
=> navigation.FindAnnotation(RelationalAnnotationNames.JsonPropertyName)?.GetConfigurationSource(); | ||
} |
Oops, something went wrong.