DbResource.cs 529 B

123456789101112131415161718192021
  1. using Benchmarks.Model;
  2. using GenHTTP.Modules.Webservices;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Benchmarks.Tests;
  5. public sealed class DbResource
  6. {
  7. private static readonly Random Random = new();
  8. [ResourceMethod]
  9. public async ValueTask<World> GetRandomWorld()
  10. {
  11. var id = Random.Next(1, 10001);
  12. await using var context = DatabaseContext.CreateNoTracking();
  13. return await context.World.FirstOrDefaultAsync(w => w.Id == id).ConfigureAwait(false);
  14. }
  15. }