Add example query with tracking disabled.
This can also be done globally, see context file.
This commit is contained in:
parent
51eb8b117a
commit
1aae643a78
@ -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;
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user