Skip to content

Commit

Permalink
refactor: change FirstAsync into FirstOrDefaultAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaVetnic committed Jan 29, 2024
1 parent 107ef6a commit 68c9ed6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ConsumerApi/DevicesDbContextSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using MediatR;
using Microsoft.EntityFrameworkCore;

// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract

namespace Backbone.ConsumerApi;

public class DevicesDbContextSeeder : IDbSeeder<DevicesDbContext>
Expand Down Expand Up @@ -34,7 +36,7 @@ private async Task SeedEverything(DevicesDbContext context)

private static async Task<Tier?> GetBasicTier(DevicesDbContext context)
{
return await context.Tiers.GetBasicTier(CancellationToken.None) ?? null;
return await context.Tiers.GetBasicTier(CancellationToken.None);
}

private async Task SeedApplicationUsers(DevicesDbContext context)
Expand All @@ -57,9 +59,7 @@ private async Task AddBasicTierToIdentities(DevicesDbContext context)
{
var basicTier = await GetBasicTier(context);
if (basicTier == null)
{
return;
}

await context.Identities.Where(i => i.TierId == null).ExecuteUpdateAsync(s => s.SetProperty(i => i.TierId, basicTier.Id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class TierQueryableExtensions
{
public static async Task<Tier?> GetBasicTier(this IQueryable<Tier> query, CancellationToken cancellationToken)
{
var basicTier = await query.FirstAsync(t => t.Name == TierName.BASIC_DEFAULT_NAME, cancellationToken);
var basicTier = await query.FirstOrDefaultAsync(t => t.Name == TierName.BASIC_DEFAULT_NAME, cancellationToken);
return basicTier;
}
}

0 comments on commit 68c9ed6

Please sign in to comment.