diff --git a/BenchmarkService.cs b/BenchmarkService.cs index d0a958d..8eb230d 100644 --- a/BenchmarkService.cs +++ b/BenchmarkService.cs @@ -88,7 +88,38 @@ public List GetAuthors() [Benchmark] public List GetAuthors_Optimized() { - List authors = new List(); + using var dbContext = new AppDbContext(); + + var authors = dbContext + .Authors + .Where(x => + x.Country == "Serbia" && + x.Age == 27) + .OrderByDescending(x => x.BooksCount) + .Select(x => new AuthorDTO + { + UserFirstName = x.User.FirstName, + UserLastName = x.User.LastName, + UserEmail = x.User.Email, + UserName = x.User.UserName, + AllBooks = x.Books + .Select(y => new BookDto + { + Id = y.Id, + Name = y.Name, + Published = y.Published + }).ToList(), + AuthorAge = x.Age, + AuthorCountry = x.Country, + Id = x.Id + }) + .Take(2) + .ToList(); + + foreach (var author in authors) + { + author.AllBooks = author.AllBooks.Where(b => b.Published.Year < 1900).ToList(); + } return authors; } diff --git a/OptimizeMePlease.csproj b/OptimizeMePlease.csproj index 7e4fcc9..c898ab0 100644 --- a/OptimizeMePlease.csproj +++ b/OptimizeMePlease.csproj @@ -2,16 +2,16 @@ Exe - netcoreapp3.1 + net6.0 - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive