使用EF存档记录的简单方法 [英] Easy way on archiving record with EF
本文介绍了使用EF存档记录的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不想从DB中删除记录,只是将其复制到归档表中,以避免事故。
我发现我们可以使用自定义存储过程。但是我们不能只是添加一个删除存储过程,我们必须添加存储过程以进行选择和更新。
有没有内置或更简单的方式做到这一点?
我只需要保留删除的记录,以防万一。
I want not to delete record from DB, but just copy it to archive table just to avoid accidents. What I found out is we can use custom stored procedure. But we cannot just add a delete stored procedure, we have to add stored procedure for select and update also. Is there any built-in or easier way on doing that? I just need to keep the deleted records, just in case..
推荐答案
我可能会去单独的归档表和从常规表中删除的触发器,类似于:
I'd probably go with a separate archive table, and a trigger on deletion from the regular table, something like:
CREATE TRIGGER Foo_AD
ON dbo.Foo
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
insert Archive_Foo (a, b)
select a, b from deleted
END
GO
这篇关于使用EF存档记录的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文