Contoh composite key adalah tabel plan_account. Id unik plan_account adalah kombinasi plan_id dan account_id.
Jika tidak ditangani, composite key akan menghasilkan error pada ASP MVC.
Business.Entities.plan_account: : EntityType ‘plan_account’ has no key defined. Define the key for this EntityType.
plan_account: EntityType: EntitySet ‘plan_account’ is based on type ‘plan_account’ that has no keys defined.
Solusinya adalah dengan menambahkan baris di bawah pada file *.Context.cs
[code language=”csharp”]
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<plan_account>().HasKey(p => new { p.plan_id, p.account_id });
}
[/code]
