DbResource.cs 604 B

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