EF FluentAPI compound key

0

I'm having trouble defining a compound key relationship in FluentAPI. I have the following entities: Product, Private Person and Stock. I need in the stock table I have a Product FK (ProductID) and a PersonFilial (FilialID) FK so that it is not possible to include the same product twice for a branch in my stock.

    
asked by anonymous 02.04.2017 / 13:07

1 answer

0

Do you need to be fluent? I usually do it by notation, see:

public class Estoque
{
    [Key, Column(Order = 1)]
    public int ProductID { get; set; }

    [Key,Column(Order = 2)]
    public int FilialID { get; set; }

}

But for Fluent it looks like this:

modelBuilder.Entity<Estoque>().HasKey(s => new { s.ProductID , s.FilialID });
    
03.06.2017 / 04:31