申し立てをグループ化してAspNet IDを拡張しようとしています。私は新しいQueryAppGroupエンティティでこれをやっています。私は&特定のグループからのクレームを削除することができるようにしたい。ので、ここで私の計画での追加は大丈夫だったが、私は(IDによって例えば、)特定の主張を取り除くのない方法を見つけることができません:ジェネリックスを使用してクラスをインターフェイスに変換できません
がIdentityUserClaimが1対ゼロを有するようにQueryAppGroupClaimと呼ばれる仲介エンティティを作成します。それと1つの関係。
特定のQueryAppGroupClaimエンティティを削除すると、削除はIdentityUserClaimにカスケードする必要があります。これを行うには
- 、私は戻ってQueryAppGroupClaimにナビゲーションプロパティをIdentityUserClaimを拡張する必要があります(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)
{
}
//...
}
私はpublic ApplicationUserManager(ApplicationUserStore store) : base(store)
ときにcompiliationエラーを取得していますArgument 1: cannot convert from 'ApplicationUserStore' to 'Microsoft.AspNet.Identity.IUserStore<ApplicationUser>'
という基本コンストラクタを呼び出します。私のクラスApplicationUserStoreはUserStoreを拡張しています。それ自体はIUserStoreというインターフェースを実装しています。 これを解決する方法がわかりません。助けてください。
主な目的を簡単にするための提案も歓迎します。
こんにちはスコットは、 'ApplicationUserStore'が問題を解決するには、' 'IUserStoreを実装しましたか?まだ問題がある場合、私はいくつかの考えを持っています。 –
Peter
はい、これは私のアプリが期待どおりに動作するように私のモデルを微調整することができました、ありがとう! –