无法将 Class 转换为泛型接口
can't convert Class to Interface with Generics
我正在尝试通过分组声明来扩展 AspNet Identity。我正在使用新的 QueryAppGroup 实体执行此操作。我希望能够添加和删除任何特定组的声明。添加没问题,但我找不到删除特定声明的方法(例如,通过 Id)所以这是我的计划:
创建一个名为 QueryAppGroupClaim 的中间实体,以便 IdentityUserClaim 与其具有一对零或一的关系。
通过删除任何特定的 QueryAppGroupClaim 实体,删除应该级联到 IdentityUserClaim。
- 为此,我需要通过导航 属性 将 IdentityUserClaim 扩展回 QueryAppGroupClaim(请参阅 ApplicationUserClaim)
代码:
public class ApplicationUserClaim : IdentityUserClaim<string>
{
[ForeignKey("QueryAppGroupClaim")]
public virtual int QueryAppGroupClaimId { get; set; }
public virtual QueryAppGroupClaim QueryAppGroupClaim { get; set; }
}
public class QueryAppGroup
{
public QueryAppGroup()
{
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("ApplicationUser")]
public String UserId { get; set; }
public String Desc { get; set; }
public String ImpersonateClaimType { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
public class QueryAppGroupClaim
{
public QueryAppGroupClaim()
{ }
[Key, ForeignKey("IdentityUserClaim")]
public int ClaimId { get; set; }
public virtual ApplicationUserClaim IdentityUserClaim { get; set; }
[ForeignKey("QueryAppGroup")]
public int QueryAppGroupId { get; set; }
public virtual QueryAppGroup QueryAppGroup { get; set; }
}
public class ApplicationUser : IdentityUser<string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>, IUser, IUser<string>
{
//...
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>
{
//...
public DbSet<QueryAppGroup> QueryAppGroups { get; set; }
public DbSet<QueryAppGroupClaim> QueryAppGroupClaims { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUserClaim>()
.HasOptional(t => t.QueryAppGroupClaim)
.WithRequired(t => t.IdentityUserClaim)
.WillCascadeOnDelete();
}
}
public class ApplicationUserStore : UserStore<ApplicationUser,IdentityRole,string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>
{
//...
//Already exists with an override of RemoveClaimAsync(...)
}
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}
public ApplicationUserManager(ApplicationUserStore store)
: base(store)
{
}
//...
}
我在调用基础构造函数 Argument 1: cannot convert from 'ApplicationUserStore' to 'Microsoft.AspNet.Identity.IUserStore<ApplicationUser>'
时收到 public ApplicationUserManager(ApplicationUserStore store) : base(store)
的编译错误。我的 class ApplicationUserStore 扩展了 UserStore,它本身实现了许多接口,一个是 IUserStore。
我看不出如何解决这个问题。请帮忙。
我们也欢迎任何让主要 objective 更简单的建议!
尝试显式实现 IUserStore<ApplicationUser>
以及 UserStore
的基本 class 声明,如下所示:
public class ApplicationUserStore :
UserStore<ApplicationUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>,
IUserStore<ApplicationUser>
{
public ApplicationUserStore(DbContext context) : base(context)
{
}
}
我正在尝试通过分组声明来扩展 AspNet Identity。我正在使用新的 QueryAppGroup 实体执行此操作。我希望能够添加和删除任何特定组的声明。添加没问题,但我找不到删除特定声明的方法(例如,通过 Id)所以这是我的计划:
创建一个名为 QueryAppGroupClaim 的中间实体,以便 IdentityUserClaim 与其具有一对零或一的关系。
通过删除任何特定的 QueryAppGroupClaim 实体,删除应该级联到 IdentityUserClaim。
- 为此,我需要通过导航 属性 将 IdentityUserClaim 扩展回 QueryAppGroupClaim(请参阅 ApplicationUserClaim)
代码:
public class ApplicationUserClaim : IdentityUserClaim<string>
{
[ForeignKey("QueryAppGroupClaim")]
public virtual int QueryAppGroupClaimId { get; set; }
public virtual QueryAppGroupClaim QueryAppGroupClaim { get; set; }
}
public class QueryAppGroup
{
public QueryAppGroup()
{
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("ApplicationUser")]
public String UserId { get; set; }
public String Desc { get; set; }
public String ImpersonateClaimType { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
public class QueryAppGroupClaim
{
public QueryAppGroupClaim()
{ }
[Key, ForeignKey("IdentityUserClaim")]
public int ClaimId { get; set; }
public virtual ApplicationUserClaim IdentityUserClaim { get; set; }
[ForeignKey("QueryAppGroup")]
public int QueryAppGroupId { get; set; }
public virtual QueryAppGroup QueryAppGroup { get; set; }
}
public class ApplicationUser : IdentityUser<string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>, IUser, IUser<string>
{
//...
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>
{
//...
public DbSet<QueryAppGroup> QueryAppGroups { get; set; }
public DbSet<QueryAppGroupClaim> QueryAppGroupClaims { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUserClaim>()
.HasOptional(t => t.QueryAppGroupClaim)
.WithRequired(t => t.IdentityUserClaim)
.WillCascadeOnDelete();
}
}
public class ApplicationUserStore : UserStore<ApplicationUser,IdentityRole,string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>
{
//...
//Already exists with an override of RemoveClaimAsync(...)
}
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}
public ApplicationUserManager(ApplicationUserStore store)
: base(store)
{
}
//...
}
我在调用基础构造函数 Argument 1: cannot convert from 'ApplicationUserStore' to 'Microsoft.AspNet.Identity.IUserStore<ApplicationUser>'
时收到 public ApplicationUserManager(ApplicationUserStore store) : base(store)
的编译错误。我的 class ApplicationUserStore 扩展了 UserStore,它本身实现了许多接口,一个是 IUserStore。
我看不出如何解决这个问题。请帮忙。
我们也欢迎任何让主要 objective 更简单的建议!
尝试显式实现 IUserStore<ApplicationUser>
以及 UserStore
的基本 class 声明,如下所示:
public class ApplicationUserStore :
UserStore<ApplicationUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, ApplicationUserClaim>,
IUserStore<ApplicationUser>
{
public ApplicationUserStore(DbContext context) : base(context)
{
}
}