我Include在我的 aspnet 核心專案中使用了很多EF 物體。我現在的產品日志中散落著這些:
13:49:54.0149751|Warn|Microsoft.EntityFrameworkCore.Query|Compiling a
query which loads related collections for more than one collection
navigation either via 'Include' or through projection but no
'QuerySplittingBehavior' has been configured. By default Entity
Framework will use 'QuerySplittingBehavior.SingleQuery' which can
potentially result in slow query performance. See
https://go.microsoft.com/fwlink/?linkid=2134277 for more information.
To identify the query that's triggering this warning call
'ConfigureWarnings(w =>
w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'
我想一起禁用警告或在它被記錄之前過濾它。
我使用nlog.web并配置了日志記錄appSettings.json
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore": "Warning",
"IdentityServer4": "Information"
}
uj5u.com熱心網友回復:
您可以通過配置 DbContext 來禁用該訊息的警告。在OnConfiguring方法中,添加這一行:
optionsBuilder
.ConfigureWarnings(x => x.Ignore(RelationalEventId.MultipleCollectionIncludeWarning));
但是,我建議首先修復導致此問題的查詢 - 這些警告的存在是有充分理由的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347653.html
