没有从 ApplicationUser 到 Microsoft.AspNet.Identity.EntityFramework.IdentityUser 的隐式引用转换

There is no implicit reference conversion from ApplicationUser to Microsoft.AspNet.Identity.EntityFramework.IdentityUser

我正在尝试在 UserStore 的通用参数上试验并传递自定义 IdentityUser。 所以我继承了 IdentityUser 并使用它所需的通用参数实现了所有必需的接口。

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;

class Program
{
    static void Main(string[] args)
    {
        var userStore = new UserStore<AppUser>(); //This is line that's triggering the error. AppUser has inherited all IdentityUser requirements, but I am not sure what I am missing here.
    }
}

AppUser 有以下实现:

public class AppUser : IdentityUser<int, AppLogin, AppRole, AppClaim>
{

}

public class AppLogin : IdentityUserLogin<int>
{

}

public class AppRole : IdentityUserRole<int>
{

}

public class AppClaim : IdentityUserClaim<int>
{

}

但问题是,由于这个错误,它没有构建成功:

Error CS0311 The type 'CustomIdentity.AppUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserStore'. There is no implicit reference conversion from 'CustomIdentity.AppUser' to 'Microsoft.AspNet.Identity.EntityFramework.IdentityUser'.

我已经检查过 post: 但它的 IdentityUser 不是我在代码中所做的自定义。

这是我的答案,我只是错过了定义,敏锐地观察Intellisense可以解决这种情况:

var userStore = new UserStore<AppUser, AppRole, int, AppLogin, AppUserRole, AppClaim>(new MyDbContext(""));

下面是 类 的定义:

public class AppUser : IdentityUser<int, AppLogin, AppUserRole, AppClaim>
{}

public class AppLogin : IdentityUserLogin<int>
{}

public class AppUserRole : IdentityUserRole<int>
{}

public class AppClaim : IdentityUserClaim<int>
{}

public class AppRole : IdentityRole<int, AppUserRole>
{}

这只是一个过度简化的解释和代码,但是这将编译并且您将了解如何自定义它。但以一种简单的方式,您可以在几行中完成此操作,因为下面的代码是第一个覆盖定义。

var userStoreSimplified = new UserStore<AppUserSimplified>();

Class定义:

public class AppUserSimplified : IdentityUser
{}