-
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
54 changed files
with
3,925 additions
and
127 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
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
// 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.Extensions.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 IsOrdinalKey(this IReadOnlyProperty property) | ||
=> property.IsKey() | ||
&& property.Name == "Id" | ||
&& property.IsShadowProperty() | ||
&& property.ClrType == typeof(int); | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
// 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> | ||
/// TODO | ||
/// </summary> | ||
public static NavigationBuilder HasJsonPropertyName( | ||
this NavigationBuilder navigationBuilder, | ||
string? name) | ||
{ | ||
Check.NullButNotEmpty(name, nameof(name)); | ||
|
||
navigationBuilder.Metadata.SetJsonPropertyName(name); | ||
|
||
return navigationBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static NavigationBuilder<TSource, TTarget> HasJsonPropertyName<TSource, TTarget>( | ||
this NavigationBuilder<TSource, TTarget> navigationBuilder, | ||
string? name) | ||
where TSource : class | ||
where TTarget : class | ||
=> (NavigationBuilder<TSource, TTarget>)HasJsonPropertyName((NavigationBuilder)navigationBuilder, name); | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
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> | ||
/// TODO | ||
/// </summary> | ||
public static bool CanSetJsonPropertyName( | ||
this IConventionNavigationBuilder navigationBuilder, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
=> navigationBuilder.CanSetAnnotation(RelationalAnnotationNames.JsonPropertyName, name, fromDataAnnotation); | ||
} |
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
// 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> | ||
/// TODO | ||
/// </summary> | ||
public static string? GetJsonPropertyName(this IReadOnlyNavigationBase navigation) | ||
=> (string?)navigation.FindAnnotation(RelationalAnnotationNames.JsonPropertyName)?.Value | ||
?? (!navigation.DeclaringEntityType.IsMappedToJson() ? null : navigation.Name); | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static void SetJsonPropertyName(this IMutableNavigationBase navigation, string? name) | ||
=> navigation.SetOrRemoveAnnotation( | ||
RelationalAnnotationNames.JsonPropertyName, | ||
Check.NullButNotEmpty(name, nameof(name))); | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
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> | ||
/// TODO | ||
/// </summary> | ||
public static ConfigurationSource? GetJsonPropertyNameConfigurationSource(this IConventionNavigationBase navigation) | ||
=> navigation.FindAnnotation(RelationalAnnotationNames.JsonPropertyName)?.GetConfigurationSource(); | ||
} |
Oops, something went wrong.