以下代码可以确保在每个特定用户的表中只有一个行:
在IdentityModels.cs文件中:
public class ApplicationUser : IdentityUser { }
public class ApplicationDbContext : IdentityDbContext
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity()
.ToTable("AspNetUsers");
}
}
在上面的实现中,重写了ODP.Net实体框架中的OnModelCreating方法并使用了modelBuilder实例来将IdentityUser类映射到'AspNetUsers”表。这确保在每个用户的表中只有一个行。
需要注意的是使用不同的数据库,代码可能需要略作修改以适合您的具体情况。