我在我的新MVC项目中添加了Identity
,我有DB
,它具有在WPF应用程序中使用的基本Account
,Customers
等表。现在一切正常,注册用户被添加到AspNetUsers
表...但我的DB
是无用的。
现在我有1000个帐户,Id
是自动增量整数,MobileNumber
和Passwords
。如何迁移AspNetUsers
中的所有内容,或者我可以更好地切换到我的表而不使用带有String的AspNetUsers
表作为Id,因为我的其他表使用Account
表?
考虑到你的情况不是很普遍,我不明白Identity会如何直接解决问题。您始终可以使用查询将数据从Account
迁移到AspNetUsers
。主要是password
和MobileNumber
(对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了