迁移到身份AspNetUsers

问题描述 投票:0回答:1

我在我的新MVC项目中添加了Identity,我有DB,它具有在WPF应用程序中使用的基本AccountCustomers等表。现在一切正常,注册用户被添加到AspNetUsers表...但我的DB是无用的。

现在我有1000个帐户,Id是自动增量整数,MobileNumberPasswords。如何迁移AspNetUsers中的所有内容,或者我可以更好地切换到我的表而不使用带有String的AspNetUsers表作为Id,因为我的其他表使用Account表?

c# entity-framework asp.net-identity
1个回答
0
投票

考虑到你的情况不是很普遍,我不明白Identity会如何直接解决问题。您始终可以使用查询将数据从Account迁移到AspNetUsers。主要是passwordMobileNumber(对username)。移动后,您可以使用ApplicationUser类覆盖任何属性。我通常做这样的事情:

[MaxLength(36)]
public override string Id { get; set; }

虽然Id仍然是一个字符串,但它是一个较小的字符串。如果你真的想把这个pk变成一个链接,那么https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-primary-key-configuration?tabs=aspnetcore2x正式提供了很长的路要走

如果你担心所有的外键都是字符串,一个简单的方法是设置一个像这样的中间模型:

public class UserIdentity
{
    public int ID { get; set; }

    public int ApplicationUserID { get; set; }
    public ApplicationUser ApplicationUser { get; set; }

}

但是,请记住,每次需要验证用户详细信息时,这将有一个额外的连接。

更新

考虑到您已经有一个表Account,其主键已经在其他表中使用过,您还可以更新您的帐户Account

public class Account 
{
    ...
    public int ApplicationUserID { get; set; }
    public ApplicationUser ApplicationUser { get; set; }
}

这样你就可以继续使用Account的fk了

© www.soinside.com 2019 - 2024. All rights reserved.