【发布时间】:2023-03-20 20:33:01
【问题描述】:
我有一列“名称”必须是唯一的。没有外键或类似的东西。
EF 6.1 最终支持通过注释创建此类索引。这已经在 SO 上讨论过了。但似乎只能通过类中的注释来完成。如何仅使用 Fluent API 做到这一点?
类似这样的:
public class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration()
{
HasKey(p => p.Id);
Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
//not possible?
Index(p => p.Name).IsUnique(); //???
}
}
【问题讨论】:
标签: c# .net entity-framework entity-framework-6 fluent-interface