I have a table (Id, name, itemst, otherproperties), Id is the primary key and I want a unique composite key (name, itemst). How can I add this using code first either by flu
Here is an example showing how to create a composite unique key via fluent API. The composite key consists of ProjectId and SectionOdKey.
public class Table
{
int Id{set;get;}
int ProjectId {set;get;}
string SectionOdKey{set;get;}
}
public class TableMap : EntityTypeConfiguration
{
this.Property(t => t.ProjectId).HasColumnName("ProjectId")
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("IX_ProjectSectionOd", 1){IsUnique = true}));
this.Property(t => t.SectionOdKey).HasColumnName("SectionOdKey")
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("IX_ProjectSectionOd", 2){IsUnique = true}));
}
- 热议问题