-
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 to the principal value generation strategy for the primary ke…
…y columns for entity types sharing the same table. Validate that properties sharing the same column have the same value generation strategy. Fixes #9652
- Loading branch information
1 parent
a866d1c
commit 92dcb80
Showing
12 changed files
with
230 additions
and
66 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
59 changes: 59 additions & 0 deletions
59
src/EFCore.Relational/Metadata/Internal/PropertyExtensions.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,59 @@ | ||
// 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 JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Internal | ||
{ | ||
/// <summary> | ||
/// Extension methods for <see cref="IProperty" /> for relational database metadata. | ||
/// </summary> | ||
public static class PropertyExtensions | ||
{ | ||
/// <summary> | ||
/// This API supports the Entity Framework Core infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public static IProperty FindSharedTablePrincipalPrimaryKeyProperty([NotNull] this IProperty property) | ||
{ | ||
var linkingRelationship = property.FindSharedTableLink(); | ||
return linkingRelationship?.PrincipalKey.Properties[linkingRelationship.Properties.IndexOf(property)]; | ||
} | ||
|
||
/// <summary> | ||
/// This API supports the Entity Framework Core infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public static IForeignKey FindSharedTableLink([NotNull] this IProperty property) | ||
{ | ||
var pk = property.GetContainingPrimaryKey(); | ||
if (pk == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var entityType = property.DeclaringEntityType; | ||
|
||
foreach (var fk in entityType.FindForeignKeys(pk.Properties)) | ||
{ | ||
if (!fk.PrincipalKey.IsPrimaryKey() | ||
|| fk.PrincipalEntityType == fk.DeclaringEntityType) | ||
{ | ||
continue; | ||
} | ||
|
||
var principalEntityType = fk.PrincipalEntityType; | ||
var entityTypeAnnotations = fk.DeclaringEntityType.Relational(); | ||
var principalTypeAnnotations = principalEntityType.Relational(); | ||
if (entityTypeAnnotations.TableName == principalTypeAnnotations.TableName | ||
&& entityTypeAnnotations.Schema == principalTypeAnnotations.Schema) | ||
{ | ||
return fk; | ||
} | ||
} | ||
|
||
return 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.