Why is there an implementation difference between

2019-08-05 09:25发布

问题:

This has no problems:

public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
    public ApplicationUserStore(MyAppDb context)
        : base(context)
    {
    }
}

While this:

public class ApplicationRoleStore : RoleStore<ApplicationRole, string, ApplicationUserRole>
{
    public ApplicationRoleStore(MyAppDb context)
        : base(context)
    {
    }
}

...produces the following compile time error:

The type 'MyApp.Models.ApplicationRole' cannot be used as a type parameter 'TRole' in the generic type or method 'Microsoft.AspNet.Identity.EntityFramework.RoleStore'. There is no implicit reference conversion from 'MyApp.Models.ApplicationRole' to 'Microsoft.AspNet.Identity.EntityFramework.IdentityRole'.

This issue came from trying to solve the issue here: Why is UserManager.CreateIdentityAsync() looking for IdentityRole and how to fix?

I don't really care which way I solve this as long as I solve it. Thanks.

回答1:

There is no issue here and no implementation difference. It must have been a hiccup. A restart of Visual Studio 2013 did not resolve the compile-time error. However, a restart of the computer did. No issue here--move along.