diff --git a/EntityFrameworkCore.Console/Program.cs b/EntityFrameworkCore.Console/Program.cs index f86e652..840233e 100644 --- a/EntityFrameworkCore.Console/Program.cs +++ b/EntityFrameworkCore.Console/Program.cs @@ -14,6 +14,20 @@ var teamFour = await context.Teams.SingleOrDefaultAsync(t => t.TeamId == 3); // Rather than raise: "System.InvalidOperationException: Sequence contains no elements." var coach = await context.Coaches.FirstOrDefaultAsync(); +async Task TrackedQuery() +{ + // EF Core tracks objects that are returned by queries. + // This is less useful in disconnected applictations like APIs and Web applications. + var teams = await context.Teams + .AsNoTracking() + .ToListAsync(); + + foreach (var team in teams) + { + Console.WriteLine(team.Name); + } +} + async Task SkipAndTakeTeams() { var recordCount = 3; diff --git a/EntityFrameworkCore.Data/DeadBallZoneLeagueDbContext.cs b/EntityFrameworkCore.Data/DeadBallZoneLeagueDbContext.cs index 0b1eaf7..b7d3a0c 100644 --- a/EntityFrameworkCore.Data/DeadBallZoneLeagueDbContext.cs +++ b/EntityFrameworkCore.Data/DeadBallZoneLeagueDbContext.cs @@ -21,6 +21,7 @@ public class DeadBallZoneLeagueDbContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite($"Data source={DbPath}") + // .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) // Do not use tracking, set globally on all queries. .LogTo(Console.WriteLine, LogLevel.Information) .EnableSensitiveDataLogging() // Do not allow this in Production. .EnableDetailedErrors(); // Do not allow this in Production.