From 657c8d7c93a3195a43de582958c54009554ca4df Mon Sep 17 00:00:00 2001 From: Adam O'Neil Date: Sun, 21 Apr 2024 06:30:35 -0400 Subject: [PATCH] no tracking by default, and sort results --- ApiAuthDemo/ApiAuthDemo/Program.Endpoints.cs | 2 +- ApiAuthDemo/ApiAuthDemo/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ApiAuthDemo/ApiAuthDemo/Program.Endpoints.cs b/ApiAuthDemo/ApiAuthDemo/Program.Endpoints.cs index bb3ca4a..e442fac 100644 --- a/ApiAuthDemo/ApiAuthDemo/Program.Endpoints.cs +++ b/ApiAuthDemo/ApiAuthDemo/Program.Endpoints.cs @@ -16,7 +16,7 @@ public static void MapApiEndpoints(this IEndpointRouteBuilder routeBuilder) { var (userName, _) = GetUserInfo(request); db.UserName = userName; - return await db.Widgets.Where(row => row.CreatedBy == userName).ToListAsync(); + return await db.Widgets.Where(row => row.CreatedBy == userName).OrderBy(row => row.Name).ToListAsync(); }); group.MapPost("/Widgets", async (ApplicationDbContext db, HttpRequest request, Widget data) => diff --git a/ApiAuthDemo/ApiAuthDemo/Program.cs b/ApiAuthDemo/ApiAuthDemo/Program.cs index c267f67..be78215 100644 --- a/ApiAuthDemo/ApiAuthDemo/Program.cs +++ b/ApiAuthDemo/ApiAuthDemo/Program.cs @@ -45,7 +45,7 @@ .AddIdentityCookies(); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); -builder.Services.AddDbContext(options => options.UseSqlServer(connectionString)); +builder.Services.AddDbContext(options => options.UseSqlServer(connectionString).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddIdentityCore(options => options.SignIn.RequireConfirmedAccount = true)