Почему не работает составной ключ в Asp.Net Core?

codename0082016

Обновляю Asp.net MVC на Core

public class Client
    {
        [Key]
        [ForeignKey("Virtual_KEY")]
        [Column(Order = 0)]
        public int Id { get; set; }
        [Key]
        [Column(Order = 1)]
        public string Id2 { get; set; }

Entity type 'Client' has composite primary key defined with data annotations. To set composite primary key, use fluent API.

1 ответ

codename0082016

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<client>()
        .HasKey(c => new { c.Id, c.Id2 });
}
</client>

licensed under cc by-sa 3.0 with attribution.