通过执行该命令,我删除了该表的行,没有任何问题。
using (var context = new SamenEntities())
{
var person = context.regs.Where(c => c.code == ID).FirstOrDefault();
if (person != null)
{
context.regs.Remove(person);
context.SaveChanges();
clearformsearch();
}
}
现在,我想在数据库中激活以下触发器:
USE [Samen]
GO
/****** Object: Trigger [dbo].[delete_after_project] Script Date: 9/11/2018 12:46:09 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[delete_after_project]
ON [dbo].[reg]
AFTER Delete
AS
BEGIN
SET NOCOUNT ON;
DECLARE @C_ID AS int
SELECT @C_ID = code FROM deleted
DELETE FROM project
WHERE id_person = @C_ID
END
激活触发器后,我在SaveChange中收到以下错误:
System.Data.Entity.Infrastructure.DbUpdateException :'更新条目时发生错误。请参阅内部异常 详细信息。”