Composite key with EF Fluentapi

Asked

Viewed 492 times

0

I’m having trouble defining a relationship with composite key in Fluentapi. I have the following entities: Product, Personal, and Stock. I need in stock table I have a product FK (Produtoid) and a Personal FK (Filialid) so that it is not possible to include twice the same product for a branch in my stock.

1 answer

0

Does it have to be effluent? I usually do 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 why Fluent is like this:

modelBuilder.Entity<Estoque>().HasKey(s => new { s.ProductID , s.FilialID });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.