public class Employee { [Key] [Column(Order = 1)] public int EmployeeId { get; set; } [Key] [Column(Order = 2)] public int BranchCode { get; set; } public string EmployeeName { get; set; } public int EmployeeAge { get; set; } public DateTime JoinDate { get; set; } public DateTime BirthDate { get; set; } public bool Active { get; set; } }
Keys (primary) - EF Core | Microsoft Docs[^]: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.
class MyContext : DbContext { public DbSet<Car> Cars { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Employee>() .HasKey(e => new { e.EmployeeId, e.BranchCode }); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)