简体   繁体   中英

EF6 - Mantaining base class record on delete

In my context I have two entities and the entity A inherits from B, they're mapped with the fluent API and works for some time.

But now I need to change it and when the base entity is deleted I need to maintain the entity in the database.

Is it possible on EF6? The default behavior is to delete the records from both tables.

I thought of changing it from inheritance to composition but would prefer to just change the delete behavior.

Thanks in advance.

It could work as long as A is not Abstract. If you delete a TPT mapped objects EF sends two delete Statements one for the base and one for the inherited table.

You could use a command interceptor to prevent the base delete from being executed or you could use stored procedure Mappings for deletion.

If A is abstract you could inherit a DeletedA class and create a corresponding entiry in the DeleteA Stored Procedure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM