私のasp.net MVCアプリケーションで、外部キー制約を削除する際に問題があります。読んでHow to delete a record with a foreign key constraint?私は、削除を処理するためのコードのいくつかのフォームが必要知っているから。 OnModelCreating
は私がApplicationUserとIdentityRoleを使用しています信じているから、それcannot change access modifiers when overriding protected inherited member
これがあると、エラーを生成しているがASP.Net MVC FK制約付きレコードの削除
は、私が現在持っていることは、次の
public override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Supplier>()
.HasOptional(j => j.Agreement)
.WithMany()
.WillCascadeOnDelete(true);
base.OnModelCreating(modelBuilder);
}
です。
私はこれを回避することはできますか、どこでコードを配置する必要がありますか?私は最初に、これを私のアイデンティティモデルに入れる必要があると思ったが、これは私が以下に示したように、しかし間違っていると思う。
namespace Mark_MVC.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
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 ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("Mark_MVC", throwIfV1Schema: false)
{
}
public override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Supplier>()
.HasOptional(j => j.Agreement)
.WithMany()
.WillCascadeOnDelete(true);
base.OnModelCreating(modelBuilder);
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Supplier> Suppliers { get; set; }
public DbSet<Agreement> Agreements { get; set; }
public DbSet<Plan> Plans { get; set; }
public DbSet<TimeSheet> TimeSheets { get; set; }
public DbSet<CustomerPlan> CustomerPlans { get; set; }
}
}
誰かがOnModelCreatingは、アクセス修飾子、あなたがそれをオーバーライドするとき、あなたが保護されたアクセス修飾子を維持する必要が保護していた
感謝