我正在尝试自定义一些使用Generics的ASP.NET Identity Core类。
我的ApplicationUser类:
//for the target size you have set the width as your tableView's width when it is already displayed on screen.
//note that when it is accesed inside viewDidLoad the tableView's bounds
//may be different to the actual bounds it will be displayed with,
//here I am just using the screen bounds
let targetSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: 10000)
//set the tableHeader's size to its size after its layout constraints are resolved
tableHeader.bounds.size = tableHeader.systemLayoutSizeFittingSize(targetSize)
//reassign it as the tableHeaderView to update the height it will be displayed in
tableView.tableHeaderView = tableHeader
我的ApplicationUserStore类:
public class ApplicationUser : IdentityUser<Guid>//, ApplicationUserClaim, ApplicationRole, ApplicationUserLogin>
{
public ApplicationUser() { }
}
错误讯息为:
&#39; AspDotNetCoreFullFramework.Identity的 ApplicationUser
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid> { public ApplicationUserStore(ApplicationDbContext ctx, IdentityErrorDescriber describer = null) : base(ctx, describer) { } }
Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8 [TUSER,TRole,TContext,TKEY的,TUserClaim,TUserRole,TUserLogin, TUserToken]&#39; 违反了类型参数的限制&#39; TUser&#39;
现在,当我转到UserStore(基类)的.NET实现时:
public class UserStore&lt; TUser,TRole,TContext,TKey&gt; : UserStore&lt; TUser,TRole,TContext,TKey, IdentityUserClaim&lt; TKey&gt;,IdentityUserRole&lt; TKey&gt;, IdentityUserLogin&lt; TKey&gt;,IdentityUserToken&lt; TKey&gt;&gt;
TUser:IdentityUser&lt; TKey&gt;
... 其中TKey:IEquatable&lt; TKey&gt; {
我可以看到ApplicationUser继承自IdentityUser&lt; GUID&gt;。 满足此约束。 TKey是实现IEquatable&lt; GUID&gt;的GUID。 这个约束也得到了满足。
那么问题是什么?
答案 0 :(得分:1)
将GUID添加到
IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();
如此post中提到的那样解决了这个问题。