从IdentityUser继承我在UserManager< User>上收到错误 [英] Inherit from IdentityUser I get an error on UserManager<User>

查看:130
本文介绍了从IdentityUser继承我在UserManager< User>上收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.NET Framework 4.5.1和Asp.Net Identity 2.1.0开发Web Api 2.2应用程序.

I'm developing a Web Api 2.2 application with .NET Framework 4.5.1 and Asp.Net Identity 2.1.0.

我不确定自己在做什么,但是我想将我的数据库与ASP.NET Identity数据库合并,而我做到了:

I'm not sure what I'm doing, but I want to merge my database with ASP.NET Identity database and I have done this:

我自己的dbContext.

public class EFDbContext : IdentityDbContext, IUnitOfWork

我自己的User类.

public class User : 
   IdentityUser<long,
                IdentityUserLogin<long>,
                IdentityUserRole<long>,
                IdentityUserClaim<long>
               >

但是当我这样做时:

UserManager<User> _userManager;

我收到此错误:

类型Data.Models.User不能用作类型TUser的参数.从Data.Models.UserMicrosoft.AspNet.Identity.IUser<string>没有任何明确的转换.

The type Data.Models.User cannot be used as parameter of type TUser. There isn't any explicit conversion from Data.Models.User to Microsoft.AspNet.Identity.IUser<string>.

之所以这样做,是因为我想将IdentityUser.Id用作long而不是string.

I'm doing this because I want to have IdentityUser.Id as long instead of string.

如何解决此错误?

更新

使用以下命令更新UserManager后:

After updating UserManager with:

UserManager<User, long> _userManager;

我在这里遇到三个错误:

I get the three errors here:

EFDbContext_ctx = context as EFDbContext;
_userManager = new UserManager<User, long>(new UserStore<User>(_ctx));

  1. "Microsoft.AspNet.Identity.UserManager.UserManager(Microsoft.AspNet.Identity.IUserStore)"的方法重载的最佳匹配具有一些无效的参数-
  2. 不能将类型'Data.Models.User'用作类型'TUser'的参数或通用方法 'Microsoft.AspNet.Identity.EntityFramework.UserStore'.没有从隐式引用从"Data.Models.User"到"Microsoft.AspNet.Identity.EntityFramework.IdentityUser"的转换.
  3. 参数1:无法从"Microsoft.AspNet.Identity.EntityFramework.UserStore"转换为"Microsoft.AspNet.Identity.IUserStore"
  1. The best match of method overload for 'Microsoft.AspNet.Identity.UserManager.UserManager (Microsoft.AspNet.Identity.IUserStore )' has some invalid arguments-
  2. The type 'Data.Models.User' cannot be used as parameter of type 'TUser' type or generic method 'Microsoft.AspNet.Identity.EntityFramework.UserStore '. There is no conversion from implicit reference from 'Data.Models.User' to 'Microsoft.AspNet.Identity.EntityFramework.IdentityUser'.
  3. Argument 1: cannot be converted from 'Microsoft.AspNet.Identity.EntityFramework.UserStore' to 'Microsoft.AspNet.Identity.IUserStore'

如何解决此新错误?

推荐答案

使用您正在使用此UserManager

代表用户的用户管理器,其中用户的主键是字符串类型.

Represents the user manager for users where the primary key for the user is of type string.

这篇关于从IdentityUser继承我在UserManager&lt; User&gt;上收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆