Skip to content

Commit

Permalink
Always scaffold [Key] attribute on all involved properties
Browse files Browse the repository at this point in the history
when DataAnnotations have been requested.

fixes dotnet#15677
  • Loading branch information
ErikEJ committed Jul 20, 2019
1 parent 2f235e9 commit 78d6e00
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,8 @@ protected virtual void GeneratePropertyDataAnnotations(
private void GenerateKeyAttribute(IProperty property)
{
var key = property.FindContainingPrimaryKey();
if (key?.Properties.Count == 1)
if (key != null)
{
if (key is IConventionKey concreteKey
&& key.Properties.SequenceEqual(KeyDiscoveryConvention.DiscoverKeyProperties(
concreteKey.DeclaringEntityType, concreteKey.DeclaringEntityType.GetProperties())))
{
return;
}

if (key.GetName() != key.GetDefaultName())
{
return;
}

_sb.AppendLine(new AttributeWriter(nameof(KeyAttribute)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Post()
Contributions = new HashSet<Contribution>();
}
[Key]
public int Id { get; set; }
public int? AuthorId { get; set; }
Expand Down

0 comments on commit 78d6e00

Please sign in to comment.