0

This is my model builder right now, but when i delete user it sets recipes userid to null.

  protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<ApplicationUser>().HasMany(e => e.Recipes).WithOne(e => e.ApplicationUser)
                .OnDelete(DeleteBehavior.Cascade);

            modelBuilder.Entity<Recipe>().HasOne(e => e.ApplicationUser).WithMany(e=>e.Recipes)

        }
Kamil Górny
  • 21
  • 1
  • 5

1 Answers1

0

I think you've overstated the mapping, you only need to map one entity to the other.

Try to use this one first;

modelBuilder.Entity<ApplicationUser>().HasMany(e => e.Recipes).OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity<Recipe>().HasOne(e => e.ApplicationUser);

If the above doesn't work, try this one alone;

modelBuilder.Entity<ApplicationUser>().HasMany(e => e.Recipes).OnDelete(DeleteBehavior.Cascade);
Kay
  • 26
  • 3