我想使用Identity Framework 1.0在MVC中开发一个应用程序,它允许用户使用其他用户使用的相同用户名进行注册.
删除用户时,我想将其IsDeleted自定义属性设置为true,而不是从数据库中删除用户.在这种情况下,另一个用户可以使用设置为true UserName的用户IsDeleted.
但默认UserManager.CreateAsync(user, password);方法是阻止这样做.
我已经覆盖了ValidateEntity的方法IdentityDbContext是这样
protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, IDictionary<object, object> items)
{
if ((entityEntry != null) && (entityEntry.State == EntityState.Added))
{
ApplicationUser user = entityEntry.Entity as ApplicationUser;
if ((user != null) && this.Users.Any<ApplicationUser>(u => string.Equals(u.UserName, user.UserName) && u.IsDeleted==false))
{
return new DbEntityValidationResult(entityEntry, new List<DbValidationError>()) {
ValidationErrors = {
new DbValidationError("User", string.Format(CultureInfo.CurrentCulture,
"", new object[] { user.UserName }))
}
};
}
IdentityRole role = entityEntry.Entity …Run Code Online (Sandbox Code Playgroud) Incorrect usage of spatial/fulltext/hash index and explicit index order我在尝试登录时收到此错误。
我没有使用实体框架迁移。
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
static ApplicationDbContext()
{
// Set the database intializer which is run once during application start
// This seeds the database with admin user credentials and admin role
Database.SetInitializer<ApplicationDbContext>(new CreateDatabaseIfNotExists<ApplicationDbContext>());
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public virtual DbSet<Category> Categories { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我在 MySQL 中自动生成数据库的代码。我没有迁移文件。