ASP.NET add migration ‘composite primary key error’ how to use fluent API

On EF core ..

Composite keys can only be configured using the Fluent API –
conventions will never setup a composite key and you can not use Data
Annotations to configure one.

Here is the Fluent API version :

Note: This is just an example. Please adjust it according to your use case.

// (In the DbContext subclass)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Attends>()
        .HasKey(c => new { c.FarmerSS, c. HotelID });
}

You can read more about it here : composite key

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)