Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用不同类型的用户表';s pk和Asp.net标识中的角色表pk_Asp.net_Asp.net Mvc_Asp.net Identity - Fatal编程技术网

如何使用不同类型的用户表';s pk和Asp.net标识中的角色表pk

如何使用不同类型的用户表';s pk和Asp.net标识中的角色表pk,asp.net,asp.net-mvc,asp.net-identity,Asp.net,Asp.net Mvc,Asp.net Identity,我试图使我的users表具有Guid类型的主键,而不是默认字符串,我的users实体如下所示: public class User : IdentityUser<Guid, UserLogin, UserRole, UserClaim> 公共类用户:IdentityUser 我的上下文类如下所示 public class Context : IdentityDbContext<User, Role, Guid, UserLogin, UserRole, UserClaim&

我试图使我的users表具有Guid类型的主键,而不是默认字符串,我的users实体如下所示:

public class User : IdentityUser<Guid, UserLogin, UserRole, UserClaim>
公共类用户:IdentityUser
我的上下文类如下所示

public class Context : IdentityDbContext<User, Role, Guid, UserLogin, UserRole, UserClaim>
公共类上下文:IdentityDbContext
但是现在,我必须使角色Id的类型为Guid,而不是像我希望的那样为int:

public class Role : IdentityRole<int, UserRole>//I can't do this because UserRole is tied to User which has Guid for TKey
public-class-Role:IdentityRole//我无法执行此操作,因为UserRole绑定到具有TKey Guid的用户

有没有办法让用户和角色对主键使用不同的类型?

遗憾的是,由于身份的可扩展性,您无法做到这一点。您对密钥类型的限制是由于实际的标识上下文,当您定义它时,您将使用此签名

IdentityDbContext<TUser, TRole, TKey>
IdentityDbContext

TKey值驱动用户和角色所需的主键类型。您可以同时使用int、string和Guid等,但不能将它们拆分为不同的类型。

我明白了,但这确实是一个严重的限制,我的意见是,无论如何还是要感谢您提供的信息。我个人不觉得它有限制性,但是…每个人都有自己的用例。如果您强烈认为应该支持GitHub,我建议您在GitHub上提出一个问题。