-
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.
Throw when an inherited property or navigation is ignored
Fixes #5864
- Loading branch information
1 parent
a8c05dd
commit 9bea6fd
Showing
16 changed files
with
615 additions
and
217 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
180 changes: 78 additions & 102 deletions
180
src/Microsoft.EntityFrameworkCore.Specification.Tests/DataAnnotationTestBase.cs
Large diffs are not rendered by default.
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
54 changes: 54 additions & 0 deletions
54
...t.EntityFrameworkCore/Metadata/Conventions/Internal/IgnoredMembersValidationConvention.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,54 @@ | ||
// 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.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal | ||
{ | ||
/// <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 class IgnoredMembersValidationConvention : IModelConvention | ||
{ | ||
/// <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 virtual InternalModelBuilder Apply(InternalModelBuilder modelBuilder) | ||
{ | ||
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) | ||
{ | ||
foreach (var ignoredMember in entityType.GetIgnoredMembers()) | ||
{ | ||
var property = entityType.FindProperty(ignoredMember); | ||
if (property != null) | ||
{ | ||
if (property.DeclaringEntityType != entityType) | ||
{ | ||
throw new InvalidOperationException(CoreStrings.InheritedPropertyCannotBeIgnored( | ||
ignoredMember, entityType.DisplayName(), property.DeclaringEntityType.DisplayName())); | ||
} | ||
Debug.Assert(false); | ||
} | ||
|
||
var navigation = entityType.FindNavigation(ignoredMember); | ||
if (navigation != null) | ||
{ | ||
if (navigation.DeclaringEntityType != entityType) | ||
{ | ||
throw new InvalidOperationException(CoreStrings.InheritedPropertyCannotBeIgnored( | ||
ignoredMember, entityType.DisplayName(), navigation.DeclaringEntityType.DisplayName())); | ||
} | ||
Debug.Assert(false); | ||
} | ||
} | ||
} | ||
|
||
return modelBuilder; | ||
} | ||
} | ||
} |
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.