配置NoTracking不需要变化追踪,我注释了。
public DemoContext() { //ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }
配置日志:
nuget包:
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder .UseLoggerFactory(ConsoleLoggerFactory) .UseSqlServer(connectionString: @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Demo;"); //base.OnConfiguring(optionsBuilder); }
public static readonly ILoggerFactory ConsoleLoggerFactory = LoggerFactory.Create(builder => { builder.AddFilter((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole(); });
效果图