SaveChangesAsync()是否等待执行触发器

时间:2018-03-21 16:36:01

标签: sql-server entity-framework triggers entity-framework-core

例如,如果在表的行插入上定义了触发器,则 在返回状态条目数之前,await context.SaveChangesAsync();将等待所有触发器完全执行吗?

1 个答案:

答案 0 :(得分:0)

Looks like any results generated by a trigger get included in the response back to your application. I'm reading this to mean that (as the comments indicate) this is part of the operation: query runs, trigger fires, back to your application. So yes triggers are executed before resuming from the await.

When a trigger fires, results are returned to the calling application, just like with stored procedures. To prevent having results returned to an application because of a trigger firing, do not include either SELECT statements that return results or statements that perform variable assignment in a trigger. A trigger that includes either SELECT statements that return results to the user or statements that perform variable assignment requires special handling; these returned results would have to be written into every application in which modifications to the trigger table are allowed. If variable assignment must occur in a trigger, use a SET NOCOUNT statement at the start of the trigger to prevent the return of any result sets.

https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql