小编Twi*_*wix的帖子

如何允许用户使用Identity Framework 1.0注册重复的UserName

我想使用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)

c# asp.net-mvc asp.net-identity

11
推荐指数
1
解决办法
4618
查看次数

空间/全文/哈希索引和显式索引顺序 EF 的使用不正确

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 中自动生成数据库的代码。我没有迁移文件。

mysql asp.net-mvc ef-code-first entity-framework-6

2
推荐指数
1
解决办法
489
查看次数