Blazor snippet samp and NRT work#24248
Conversation
|
@JeremyLikness ... I'm wrapping up all of the Blazor NRT bits with this PR 😅. Recall that I hit a problem with one NRT warning in the EFCore-Blazor Server sample app on the earlier PR that addressed sample app NRTs. I punted 🏈🦶 on it at the time 🏃. The NRT warning is in the private async Task DeleteContactAsync()
{
using var context = DbFactory.CreateDbContext();
Filters.Loading = true;
if (Wrapper is not null)
{
var contact = await context.Contacts?.FirstAsync(c => c.Id == Wrapper.DeleteRequestId);
if (contact != null)
{
context.Contacts?.Remove(contact);
await context.SaveChangesAsync();
}
}
Filters.Loading = false;
await ReloadAsync();
}The NRT warning is on the line ... var contact = await context.Contacts?.FirstAsync(c => c.Id == Wrapper.DeleteRequestId);By avoiding the use of a null conditional operator on private async Task DeleteContactAsync()
{
using var context = DbFactory.CreateDbContext();
Filters.Loading = true;
if (Wrapper is not null && context.Contacts is not null)
{
var contact = await context.Contacts.FirstAsync(c => c.Id == Wrapper.DeleteRequestId);
if (contact is not null)
{
context.Contacts?.Remove(contact);
await context.SaveChangesAsync();
}
}
Filters.Loading = false;
await ReloadAsync();
}That works when running the app. Does that seem ok to you? The prior code runs fine, but it's probably best if we perform the update to avoid doc issues on the warning. UPDATE: I'm going to go ahead with that to get this merged. I'm trying to wrap up some things before BUGGIN' OUT ⛄. Let me know if you need a change to that ☝️ bit that I changed on the PR for |
Fixes #23064