Answer the question
In order to leave comments, you need to log in
How to count the number in a group?
There is a list of films and each has its own rating. I sorted them by rating groups and I'm trying to calculate the number by rating, i.e. how many in each movie rating. How to do it?
public static List<DVDrental> GetDataRating()
{
using (var db = new LinqToDB.Data.DataConnection(LinqToDB.ProviderName.PostgreSQL, Config.SqlConnectionString))
{
var table = db.GetTable<DVDrental>();
var list =
table.GroupBy(g => new { g.Rating })
.Select(s => new DVDrental { Rating = s.Key.Rating })
.ToList();
return list;
}
}
var ratings = Core.GetDataRating();
foreach (var rating in ratings)
{
Console.WriteLine($"Рейтинг: {rating.Rating}");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question