[英]How to prevent EF core 5 from creating a savepoint when saving
我們在始終在外部管理事務的上下文中使用 EF Core。 我們還必須使用 MARS。 由於我們已升級到 EF Core 5,因此這種組合會導致以下警告:
Microsoft.EntityFrameworkCore.Database.Transaction - Savepoints are disabled because Multiple Active
Result Sets (MARS) is enabled. If 'SaveChanges' fails, then the transaction cannot be automatically
rolled back to a known clean state. Instead, the transaction should be rolled back by the application
before retrying 'SaveChanges'. See https://go.microsoft.com/fwlink/?linkid=2149338 for more information.
To identify the code which triggers this warning, call 'ConfigureWarnings(w =>
w.Throw(RelationalEventId.SavepointsDisabledBecauseOfMARS))'.
我對禁用保存點很好(至少現在是這樣),但我對每個數據庫保存的日志消息不太滿意......
有沒有辦法告訴 EF Core 不要使用這個新功能?
事實證明,錯誤消息中描述的對ConfigureWarnings
的調用也可用於忽略該消息。
但是要注意的一件事是,與警告消息所說的相反, SavepointsDisabledBecauseOfMARS
值不是RelationalEventId
類型的一部分。 相反,它是SqlServerEventId
類型的一部分。
要忽略警告,完整的代碼如下:
ConfigureWarnings(w =>
w.Ignore(SqlServerEventId.SavepointsDisabledBecauseOfMARS))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.