-
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.
Default relationships to ownership for Cosmos
Allow to reconfigure STETs as regular entity types Fixes #24803
- Loading branch information
1 parent
4507cc3
commit 5e26c54
Showing
37 changed files
with
1,146 additions
and
283 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
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
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.Cosmos/Metadata/Conventions/CosmosInversePropertyAttributeConvention.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 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions | ||
{ | ||
/// <summary> | ||
/// A convention that configures the inverse navigation property based on the <see cref="InversePropertyAttribute" /> | ||
/// specified on the other navigation property. | ||
/// All navigations are assumed to be targeting owned entity types for Cosmos. | ||
/// </summary> | ||
public class CosmosInversePropertyAttributeConvention : InversePropertyAttributeConvention | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="InversePropertyAttributeConvention" />. | ||
/// </summary> | ||
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param> | ||
public CosmosInversePropertyAttributeConvention(ProviderConventionSetBuilderDependencies dependencies) | ||
: base(dependencies) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Finds or tries to create an entity type target for the given navigation member. | ||
/// </summary> | ||
/// <param name="entityTypeBuilder"> The builder for the referencing entity type. </param> | ||
/// <param name="targetClrType"> The CLR type of the target entity type. </param> | ||
/// <param name="navigationMemberInfo"> The navigation member. </param> | ||
/// <param name="shouldCreate"> Whether an entity type should be created if one doesn't currently exist. </param> | ||
/// <returns> The builder for the target entity type or <see langword="null"/> if it can't be created. </returns> | ||
protected override IConventionEntityTypeBuilder? TryGetTargetEntityTypeBuilder( | ||
IConventionEntityTypeBuilder entityTypeBuilder, | ||
Type targetClrType, | ||
MemberInfo navigationMemberInfo, | ||
bool shouldCreate = true) | ||
=> ((InternalEntityTypeBuilder)entityTypeBuilder) | ||
#pragma warning disable EF1001 // Internal EF Core API usage. | ||
.GetTargetEntityTypeBuilder( | ||
targetClrType, | ||
navigationMemberInfo, | ||
shouldCreate ? ConfigurationSource.DataAnnotation : null, | ||
targetShouldBeOwned: true); | ||
#pragma warning restore EF1001 // Internal EF Core API usage. | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/EFCore.Cosmos/Metadata/Conventions/CosmosRelationshipDiscoveryConvention.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,35 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions | ||
{ | ||
/// <summary> | ||
/// A convention that configures relationships between entity types based on the navigation properties | ||
/// as long as there is no ambiguity as to which is the corresponding inverse navigation. | ||
/// All navigations are assumed to be targeting owned entity types for Cosmos. | ||
/// </summary> | ||
public class CosmosRelationshipDiscoveryConvention : RelationshipDiscoveryConvention | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="RelationshipDiscoveryConvention" />. | ||
/// </summary> | ||
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param> | ||
public CosmosRelationshipDiscoveryConvention(ProviderConventionSetBuilderDependencies dependencies) | ||
: base(dependencies) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Returns a value indicating whether the given entity type should be added as owned if it isn't currently in the model. | ||
/// </summary> | ||
/// <param name="targetType"> Target entity type. </param> | ||
/// <param name="model"> The model. </param> | ||
/// <returns> <see langword="true"/> if the given entity type should be owned. </returns> | ||
protected override bool? ShouldBeOwned(Type targetType, IConventionModel model) | ||
=> true; | ||
} | ||
} |
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
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
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
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
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.