static void Main(string[] args) { var context = new GringottsContext(); //connection string used is .\SQLEXPRESS you can change it in the App.config if you need to. //19.Deposits Sum for Ollivander Family //DepositGroups(context); //20.Deposits Filter //DepositFilter(context); }
private static void DepositGroups(GringottsContext context) { string wandcrafter = "Ollivander family"; var depositGroups = context.WizzardDeposits .Where(w => w.MagicWandCreator == wandcrafter) .GroupBy(g => g.DepositGroup) .Select(s => new { Name = s.Key, DepositsAmount = s.Sum(z => z.DepositAmount) }) .ToList(); foreach (var depGroup in depositGroups) { Console.WriteLine($"{depGroup.Name} - {depGroup.DepositsAmount:F2}"); } }