ASP.NET add migration 'composite primary key error' how to use fluent API ASP.NET add migration 'composite primary key error' how to use fluent API asp.net asp.net

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 DataAnnotations 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