[#79] AppDbContext: Use compiled queries

This commit is contained in:
2026-04-04 15:28:30 +02:00
parent 9c39a2f820
commit d051a2bfcf
42 changed files with 393 additions and 379 deletions

View File

@@ -159,35 +159,20 @@ namespace Elwig.Windows {
protected override async Task OnRenewContext(AppDbContext ctx) {
await base.OnRenewContext(ctx);
FillInputs(App.Client, await ctx.Seasons.FindAsync(Utils.CurrentLastSeason));
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons
.OrderByDescending(s => s.Year)
.Include(s => s.Modifiers)
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
FillInputs(App.Client, await ctx.FetchSeasons(Utils.CurrentLastSeason).SingleOrDefaultAsync());
ControlUtils.RenewItemsSource(SeasonList, await ctx.FetchSeasons(includeModifiers: true).ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
var year = (SeasonList.SelectedItem as Season)?.Year;
ControlUtils.RenewItemsSource(BranchList, await ctx.Branches
.OrderBy(b => b.Name)
.Include(b => b.PostalDest)
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes
.OrderBy(a => a.Name)
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineVariantInput, await ctx.WineVarieties
.OrderBy(s => s.Name)
.ToListAsync());
var attrList = await ctx.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
ControlUtils.RenewItemsSource(BranchList, await ctx.FetchBranches().ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineAttributeList, await ctx.FetchWineAttributes().ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineVariantInput, await ctx.FetchWineVarieties().ToListAsync());
var attrList = await ctx.FetchWineAttributes().Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineAttributeInput, attrList);
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes
.OrderBy(t => t.VtrgId)
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations
.OrderBy(c => c.Name)
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers
.Where(m => m.Year == year)
.OrderBy(m => m.Ordering)
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.FetchWineCultivations().ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.FetchModifiers(year).ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
}
protected override void UpdateButtons() {
@@ -283,7 +268,7 @@ namespace Elwig.Windows {
using var ctx = new AppDbContext();
ClearInputStates();
FillInputs(App.Client, await ctx.Seasons.FindAsync(Utils.CurrentLastSeason));
FillInputs(App.Client, await ctx.FetchSeasons(Utils.CurrentLastSeason).SingleOrDefaultAsync());
LockInputs();
}
@@ -303,7 +288,7 @@ namespace Elwig.Windows {
using var ctx = new AppDbContext();
ClearInputStates();
FillInputs(App.Client, await ctx.Seasons.FindAsync(Utils.CurrentLastSeason));
FillInputs(App.Client, await ctx.FetchSeasons(Utils.CurrentLastSeason).SingleOrDefaultAsync());
UpdateButtons();
}
@@ -339,7 +324,7 @@ namespace Elwig.Windows {
using (var ctx = new AppDbContext()) {
ClearInputStates();
FillInputs(App.Client, await ctx.Seasons.FindAsync(Utils.CurrentLastSeason));
FillInputs(App.Client, await ctx.FetchSeasons(Utils.CurrentLastSeason).SingleOrDefaultAsync());
LockInputs();
}
@@ -427,7 +412,7 @@ namespace Elwig.Windows {
private async Task UpdateParameters(int year) {
try {
using var ctx = new AppDbContext();
if (await ctx.Seasons.FindAsync(year) is not Season s)
if (await ctx.FetchSeasons(year).SingleOrDefaultAsync() is not Season s)
return;
s.Billing_AllowAttrsIntoLower = ParameterAllowAttrIntoLowerInput.IsChecked ?? false;