Entity Framework on delete cascade

前端 未结 5 899
天涯浪人
天涯浪人 2020-12-10 03:31

I have problem with deleting related rows in Entity Framework 4.1. I have tables with relations

Book 1<--->* BookFormats

I have set the on delete cascade

5条回答
  •  我在风中等你
    2020-12-10 03:51

    I've tested it in EF 6.1.3 and this should work fine:

     var originalBook = m.db.Book.First(x => x.BookID == bookId);
     originalBook.BookFormats.Clear();
     db.Books.Remove(originalBook);
     m.db.SaveChanges();
    

提交回复
热议问题