gpt4 book ai didi

c# - 需要将 Asp.Net Identity (RTM) User Id 从 nvarchar(128) 更改为 uniqueidentifier

转载 作者:行者123 更新时间:2023-11-30 12:09:53 24 4
gpt4 key购买 nike

使用 Asp.Net Identity 1.0(RTM 版)。默认实现创建一个 AspNetUsers 表。 Id 列类型为 nvarchar(128)。

创建数据库和表时,我只想将用户 ID 的类型更改为 uniqueidentifier 而不是 nvarchar(128)。我曾尝试在 OnModelCreating 覆盖中使用 .HasColumnType("uniqueidentifier")...但它会引发错误。

Microsoft 表示这很容易...但我倾向于不同意...

http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity

Since you control the database schema, common tasks such as changing table names or changing the data type of primary keys is simple to do.

因此,根据他们极其简短且完全非技术性的文档,这似乎是一项常见任务,即更改主键的数据类型……但似乎并不简单。请帮忙。

最佳答案

ASP.NET 团队的 Hao Kung 已在 StackOverflow 上发帖你需要实现自己的 IUserStore ,但他正在努力使 1.1 版本更容易。

我相信您不仅需要实现 IUserStore ,在我看来你需要自己的 UserStore实现为 UserStore<TUser>仅限于 IdentityUser .

如果我是正确的,这意味着您至少需要实现 IUserStore , IUserPasswordStore , IUserSecurityStampStoreIUserLoginStore .

它有 14 种方法,但其中大多数都非常容易实现。请注意,这不能完全替代 UserStore<TUser> ,这只是支持 AccountController 中使用的部件所需要的来自默认模板。

我在 GitHub 上有一个项目我自己尝试过的地方,即我实现了一个 UserStore,它使用 MongoDb 而不是 EntityFramework 来实现持久性。

关于c# - 需要将 Asp.Net Identity (RTM) User Id 从 nvarchar(128) 更改为 uniqueidentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19912049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com