[英]In ASP.NET Identity Core can I change UserToken primary key
Identity generates UserToken table for me (code first). Identity 为我生成 UserToken 表(代码优先)。 I don't like that it uses 3-part primary key and there is no specified UserTokenId column.
我不喜欢它使用 3 部分主键并且没有指定的 UserTokenId 列。
CREATE TABLE [UserToken] (
[UserId] int NOT NULL,
[LoginProvider] nvarchar(450) NOT NULL,
[Name] nvarchar(450) NOT NULL,
[Value] nvarchar(max),
CONSTRAINT [PK_UserToken] PRIMARY KEY ([UserId], [LoginProvider], [Name])
);
Is it possible to change (in my C# project code) the table to use only one id column as primary key?是否可以(在我的 C# 项目代码中)更改表以仅使用一个 id 列作为主键? Or is it actually even a good practice in this case?
或者在这种情况下它实际上是一个很好的做法?
I have read many instructions on how to change the id data type in the user table but it's a bit different case.我已经阅读了许多关于如何更改用户表中的 id 数据类型的说明,但情况略有不同。
You might change the table structure manually by creating an IDENTITY
column and by creating a UNIQUE index on the three columns in question...您可以通过创建
IDENTITY
列并在相关的三列上创建 UNIQUE 索引来手动更改表结构...
But for what reason?但出于什么原因?
The identify framework will always look up data based on the three value tuple and not on a artificial primary key which does not reflect any real data.识别框架将始终基于三值元组而不是不反映任何真实数据的人工主键来查找数据。
An identity column might make sense in case this value is used as a reference on another table, in this case there might be a reason to have a simple foreign key instead of the three value tuple.如果此值用作另一个表的引用,则标识列可能有意义,在这种情况下,可能有理由使用简单的外键而不是三值元组。
If you want to customize your table/database layout that is used by ASP.NET Identity, this post might be a good starting point (Beware that this post is based on ASP.NET core identity).如果您想自定义 ASP.NET Identity 使用的表/数据库布局, 这篇文章可能是一个很好的起点(请注意,这篇文章基于 ASP.NET 核心身份)。
Background: ASP.NET is based on a layered approach where the storage used to persist information about the ASP.NET identity information is a separate module inside the ASP.NET identity framework.背景:ASP.NET 基于分层方法,其中用于保存有关 ASP.NET 标识信息的信息的存储是 ASP.NET 标识框架内的一个单独模块。
You might use this as a starting point to create your own persistence layer with your own database model.您可以以此为起点,使用您自己的数据库模型创建您自己的持久层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.