-
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
48 changed files
with
3,154 additions
and
96 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
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 HasJsonElementName( | ||
this NavigationBuilder navigationBuilder, | ||
string? name) | ||
{ | ||
Check.NullButNotEmpty(name, nameof(name)); | ||
|
||
navigationBuilder.Metadata.SetJsonElementName(name); | ||
|
||
return navigationBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static NavigationBuilder<TSource, TTarget> HasJsonElementName<TSource, TTarget>( | ||
this NavigationBuilder<TSource, TTarget> navigationBuilder, | ||
string? name) | ||
where TSource : class | ||
where TTarget : class | ||
=> (NavigationBuilder<TSource, TTarget>)HasJsonElementName((NavigationBuilder)navigationBuilder, name); | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static IConventionNavigationBuilder? HasJsonElementName( | ||
this IConventionNavigationBuilder navigationBuilder, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
{ | ||
if (!navigationBuilder.CanSetJsonElementName(name, fromDataAnnotation)) | ||
{ | ||
return null; | ||
} | ||
|
||
navigationBuilder.Metadata.SetJsonElementName(name, fromDataAnnotation); | ||
|
||
return navigationBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static bool CanSetJsonElementName( | ||
this IConventionNavigationBuilder navigationBuilder, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
=> navigationBuilder.CanSetAnnotation(RelationalAnnotationNames.JsonElementName, name, fromDataAnnotation); | ||
} |
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
// 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 JsonElementName(this IReadOnlyNavigationBase navigation) | ||
=> (string?)navigation.FindAnnotation(RelationalAnnotationNames.JsonElementName)?.Value ?? navigation.Name; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static void SetJsonElementName(this IMutableNavigationBase navigation, string? name) | ||
=> navigation.SetOrRemoveAnnotation( | ||
RelationalAnnotationNames.JsonElementName, | ||
Check.NullButNotEmpty(name, nameof(name))); | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static string? SetJsonElementName( | ||
this IConventionNavigationBase navigation, | ||
string? name, | ||
bool fromDataAnnotation = false) | ||
{ | ||
navigation.SetOrRemoveAnnotation( | ||
RelationalAnnotationNames.JsonElementName, | ||
Check.NullButNotEmpty(name, nameof(name)), | ||
fromDataAnnotation); | ||
|
||
return name; | ||
} | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static ConfigurationSource? GetJsonElementNameConfigurationSource(this IConventionNavigationBase navigation) | ||
=> navigation.FindAnnotation(RelationalAnnotationNames.JsonElementName)?.GetConfigurationSource(); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.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,49 @@ | ||
// 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="OwnedNavigationBuilder" />. | ||
/// </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 RelationalOwnedNavigationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> ToJson<TOwnerEntity, TDependentEntity>( | ||
this OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> builder, | ||
string jsonColumnName) | ||
where TOwnerEntity : class | ||
where TDependentEntity : class | ||
{ | ||
builder.OwnedEntityType.SetJsonColumnName(jsonColumnName); | ||
|
||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public static OwnedNavigationBuilder ToJson( | ||
this OwnedNavigationBuilder builder, | ||
string? jsonColumnName = null) | ||
{ | ||
if (jsonColumnName == null) | ||
{ | ||
// TODO: is this guaranteed to be false here, or should we be more defensive? | ||
var navigationName = builder.Metadata.GetNavigation(pointsToPrincipal: false)!.Name; | ||
builder.OwnedEntityType.SetJsonColumnName(navigationName); | ||
} | ||
else | ||
{ | ||
builder.OwnedEntityType.SetJsonColumnName(jsonColumnName); | ||
} | ||
|
||
return builder; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.