1

I am using code first for my prject using sql server. I have 2 class models that one inherits the other. and I have dbsets for the base class and its inherited class. The base class contains some record I want to remove. I want the relevant record to be removed and also its inherited record. Can someone help me with how to do it? TY

davidmoshko
  • 223
  • 1
  • 4
  • 8
  • With inheritance you always only delete one entity and EF will delete the appropriate records depending on the inheritance strategy you chose. – Gert Arnold Jun 21 '16 at 21:07

1 Answers1

0

Cascade delete term means you want to remove the related rows from other tables. This is something different from what you want.

The given below listed approaches can help you to solve your problem:

1) You can use SQL trigger todo that: SQL Server ON DELETE Trigger Define your SQL trigger on delete and this trigger will removes the related rows

2) You can use sqldependency https://msdn.microsoft.com/de-de/library/62xk7953(v=vs.110).aspx Same as trigger but in C#

3) You can use IDbCommandTreeInterceptor: http://www.codeguru.com/csharp/csharp/soft-deleting-entities-cleanly-using-entity-framework-6-interceptors.html Modify the query before you sent it to the SQL Server

My recommendation for you just keep it simple. Use the Repostiory pattern and by Delete apply your deletion rules manually (search for the related entities and delete them)

Community
  • 1
  • 1
Bassam Alugili
  • 16,345
  • 7
  • 52
  • 70