Say I have the following table with the following data
And I want to insert a new record of {Paul, 30, M}.
I want the DBContext to reject this. Essentially what I want is the Name, Age and Gender to be unique in combo. No record can have the same name, age or gender.
public class MyModel
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Gender { get; set; }
}
My Context is setup to just have a key
public class MyContext : DbContext
{
public DbSet<MyModel> MyModels { get; set; }
public override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MyModel>()
.HasKey(o => new { o.Id });
}
}
