我有以下代码第一实体:
class Role
{
[Key]
public int Id { get; set; }
[Index("NameIndex", IsUnique = true)]
public string Name { get; set; }
}
但是在使用 SQL Management Studio 检查数据库时,有多个同名的行:
ID=1, Name=admin
ID=2, Name=admin
我的上下文很简单:
class MemberContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
}
检查 SQL 2014 Express 数据库表索引,没有生成(只有 PK 存在)。
有什么我没有做的事情需要索引才能工作吗?