-
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.
Resolves #19246 Also related #19964 - Add KeylessAttribute in Abstractions packge - Add convention to detect KeylessAttribute and configure the entityType to be keyless - Scaffolding when using data annotations - Generate KeylessAttribute over entity class - Skip HasNoKey from fluent API configuration Tests: - Add tests for OwnedAttribute - Add tests for KeylessAttribute - Add test for scaffolding to verify behavior with data annotations
- Loading branch information
Showing
9 changed files
with
297 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Marks a type as keyless entity. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public sealed class KeylessAttribute : Attribute | ||
{ | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/EFCore/Metadata/Conventions/KeylessEntityTypeAttributeConvention.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,39 @@ | ||
// 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.ComponentModel.DataAnnotations.Schema; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions | ||
{ | ||
/// <summary> | ||
/// A convention that ignores entity types that have the <see cref="KeylessAttribute" />. | ||
/// </summary> | ||
public class KeylessEntityTypeAttributeConvention : EntityTypeAttributeConventionBase<KeylessAttribute> | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="KeylessEntityTypeAttributeConvention" />. | ||
/// </summary> | ||
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param> | ||
public KeylessEntityTypeAttributeConvention([NotNull] ProviderConventionSetBuilderDependencies dependencies) | ||
: base(dependencies) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Called after an entity type is added to the model if it has an attribute. | ||
/// </summary> | ||
/// <param name="entityTypeBuilder"> The builder for the entity type. </param> | ||
/// <param name="attribute"> The attribute. </param> | ||
/// <param name="context"> Additional information associated with convention execution. </param> | ||
protected override void ProcessEntityTypeAdded( | ||
IConventionEntityTypeBuilder entityTypeBuilder, | ||
KeylessAttribute attribute, | ||
IConventionContext<IConventionEntityTypeBuilder> context) | ||
{ | ||
entityTypeBuilder.HasNoKey(fromDataAnnotation: 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
Oops, something went wrong.