using System.Linq;
using Microsoft.EntityFrameworkCore;
using QueryingDemo.Model;

namespace QueryingDemo.Samples
{
    public class Sample3 : ISample
    {
        public int Number => 3;
        public string Title => "SELECT specific columns";

        public void Run(NorthwindContext dc)
        {
            var result = dc.Products
                .Where(p => EF.Functions.Like(p.ProductName, "%a%"))
                .Select(p => new
                {
                    Id = p.ProductId,
                    Name = p.ProductName,
                    SupplierName = p.Supplier.CompanyName,
                    OrderedQuantity = p.OrderDetails.Sum(d => d.Quantity)
                })
                .ToList();
        }
    }
}