【问题标题】:There is no implicit reference conversion from ApplicationUser to IdentityUser没有从 ApplicationUser 到 IdentityUser 的隐式引用转换
【发布时间】:2016-07-03 18:00:05
【问题描述】:

我正在尝试自定义一些使用泛型的 ASP.NET Identity Core 类。

我的 ApplicationUser 类:

public class ApplicationUser : IdentityUser<Guid>//, ApplicationUserClaim, ApplicationRole, ApplicationUserLogin> 
{
    public ApplicationUser() {  }
}

我的 ApplicationUserStore 类:

public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid> 
{
    public ApplicationUserStore(ApplicationDbContext ctx, IdentityErrorDescriber describer = null) : base(ctx, describer)
    {

    }
}

错误信息是:

'AspDotNetCoreFullFramework.Identity.ApplicationUser1[System.Guid]', onMicrosoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken]' 违反类型参数'TUser'的约束

现在,当我转到 UserStore(基类)的 .NET 实现时:

公共类 UserStore : UserStore, IdentityUserRole, IdentityUserLogin, IdentityUserToken>
其中 TUser : IdentityUser
... 其中 TKey : IEquatable {

我可以看到 ApplicationUser 继承自 IdentityUser。 这个约束得到满足。 TKey 是实现 IEquatable 的 GUID。 这个约束也满足了。

那么问题出在哪里?

【问题讨论】:

  • 或者指向我关于这个问题的参考..
  • 您在身份方面到底想要做什么,您能否更详细地解释一下。我认为这可能有助于其他人指出您采取不同的方法..跨度>
  • 我只想实现 ASP.NET Identity API 尽可能可定制,以便将其用作未来项目的模板。稍后我可以看看它,无需太多探索。

标签: c# generics entity-framework-6 asp.net-identity entity-framework-core


【解决方案1】:

将 GUID 添加到

IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();

正如post 中提到的那样,解决了这个问题。

【讨论】:

  • 你在哪里添加这个? Startup.cs?
  • 我猜很久以前在 ConfigureServices 下。
猜你喜欢
  • 1970-01-01
  • 2017-11-25
  • 2019-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-16
相关资源
最近更新 更多