So, you use Entity Framework Core, and you usually code your selects like the following, maybe you are getting too much data.

var products = Products
    .Where(p => p.UnitsInStock > 0)
    .OrderBy(p => p.ProductName)
    .ToList()

Running the query above, on my table, you'll get the following output, take a look at how many columns you are getting back from your database.

Screenshot with every single column

In my case, I only care about the Title, PublishedData, and a small description. So to get back only these fields, we have a few options. In the first one, we'll set the fields and return them as a dynamic object, the second one, is to give the .NET a class to use.

var products = Products

    .Select(p => new {p.ProductID, p.ProductName, p.UnitsInStock, p.UnitPrice})
    //.Select(p => new ProductDTO {p.ProductID, p.ProductName, p.UnitsInStock, p.UnitPrice})

    .Where(p => p.UnitsInStock > 0)
    .OrderBy(p => p.ProductName)
    .ToList()

Screenshot with fewer columns and also fewer data size


Translations:




Comments

comments powered by Disqus

Newsletter

Sua assinatura não pôde ser validada.
You subscribed successfully!

Newsletter

Subscribe for Newsletter