2016-12-03 36 views
0

有没有办法在fluente API中创建一个基于某个值的堆肥唯一索引?实体流利的API - 堆肥唯一索引

例:

string code { get; set; } 
bool active { get; set; } 


Property(x => x.code) 
      .HasMaxLength(6) 
      .HasColumnAnnotation(
       IndexAnnotation.AnnotationName, 
       new IndexAnnotation(new IndexAttribute("IX_CODE", 1) { IsUnique = true })) 
      .IsRequired(); 

Property(x => x.active) 
      //I want this only if "active == true" 
      .HasColumnAnnotation(
       IndexAnnotation.AnnotationName, 
       new IndexAnnotation(new IndexAttribute("IX_CODE", 2) { IsUnique = true })) 
      .IsRequired(); 

这并不适合我,因为我希望我的“代码”是独一无二的,只有当我的“活跃”是真实的,否则我可以有重复码(有效==假)。

任何人都知道一种方式?

回答

1

恐怕你不能那样做。但是,您可以使用TPH创建两种不同的类型,然后对每一种应用不同的规则。