ApplicationUser(IdentityUser)から継承したクラスで、削除、 クラスは次のとおりです。これは私のApplicationUserクラスはカスケードは、私はASP .NETアイデンティティにApplicationUserから継承されている2つのクラスを持っている
ある
public class ApplicationUser : IdentityUser
{
public string Name { get; set; }
public string Surname { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
それを継承し、二つのクラス:
public class User : ApplicationUser
{
public virtual ICollection<Repair> Repairs { get; set; }
public virtual ICollection<Vehicle> Vehicles { get; set; }
}
public class Repairer : ApplicationUser
{
public virtual ICollection<Repair> Repairs { get; set; }
}
私はコードファーストマイグレーションを実行すると、両方のクラスが同じテーブル内whicですhは適切なDiscriminatorと役割を持つAspNetUsersテーブルです。問題は、私がシステムからいくつかのユーザーを削除すると、すべての車両と修理がデータベースから削除されてもらいたいのですが、データベースではディスクリミネータの隣に適切な区別がないので、データベース内の適切なテーブル(Vehicle and Repair)を参照する外部キー制約でカスケード削除を行うので、代わりに例外が発生するか、dbの外部キーがnullに設定されます。
カスケード削除を達成する方法ですか、それ以外はすべてうまく動作しているため、モデルを変更する必要があります。
ありがとうございます!