0

Managing lists as databases in C#

I created a List in C# like a “database” to save drinks from restaurant in my project, but now I have to show best-selling drink, can you help me doing it? It’s for a school project, we haven’t advanced to SQL, so don’t judge.

10th Dec 2020, 1:55 AM
Florentina
2 ответов
+ 2
If I understand correctly, you have created a database. You have used the entity framework. Now you want to sort the products based on sales. As you know Entity Framework Core is a modern object-database mapper for .NET. It supports LINQ queries. So you can use groupby and aggregation and then sort data based on sales by OrderBy. var summaryApproach1 = transactions.GroupBy(t => t.Category) .Select(t => new { Category = t.Key, Count = t.Count(), Amount = t.Sum(ta => ta.Amount), }).ToList(). OrderBy(o=>Amount); https://riptutorial.com/csharp/example/17012/groupby-sum-and-count
10th Dec 2020, 8:49 PM
hossein B
hossein B - avatar
0
thank you so muuuch hossein B , how could I not remember this
10th Dec 2020, 11:59 PM
Florentina