ایجاد ایندکس منحصربفرد در EF Code first به صورت Fluent API
نویسنده: سیروان عفیفی
تاریخ: ۱۳۹۴/۰۴/۱۶ ۱۸:۱۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public class SubCategory : BaseEntity
{
public string Title { get; set; }
[ForeignKey("CategoryId")]
public virtual Category Category { get; set; }
public Guid CategoryId { get; set; }
} public class SubCategoryConfiguration : EntityTypeConfiguration<SubCategory>
{
public SubCategoryConfiguration()
{
Property(p => p.CategoryId).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("AK_SubCategory", 1){ IsUnique = true}));
Property(p => p.Title).HasMaxLength(30).IsRequired().HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("AK_SubCategory", 2){ IsUnique = true}));
Property(so => so.RowVersion).IsRowVersion();
}
} public virtual bool IsClustered { get; set; }
public virtual int Order { get; set; }
public virtual bool IsUnique { get; set; } Property(p => p.Title).HasMaxLength(30).IsRequired().HasColumnAnnotation("Index", new IndexAnnotation(new[]
{
new IndexAttribute("AK_Category_1") { IsUnique = true},
new IndexAttribute("AK_Category_2"),
}));