Answer the question
In order to leave comments, you need to log in
How to group a list?
Tell me how to group a list from a database using linq?
Here is the code where I connect and get the necessary data from the database, but there are repetitions and I need to group them somehow.
How to do it?
public static List<DataActor20MoviesInfo> GetDataActor20Movies()
{
using (var db = new LinqToDB.Data.DataConnection(LinqToDB.ProviderName.PostgreSQL, Config.SqlConnectionString))
{
var list = (from actor in db.GetTable<DVDrentalActor>()
join film in (db.GetTable<DVDrentalFilmActor>())
on actor.ID equals film.ActorID
select new
{
ActorID = actor.ID,
FilmActorID = film.ActorID,
FirstName = actor.FirstName,
LastName = actor.LastName
}
)
.Select(s => new DataActor20MoviesInfo
{
ActorID = s.ActorID,
FilmActorID = s.FilmActorID,
FirstName = s.FirstName,
LastName = s.LastName
})
.ToList();
return list;
}
}
public class DataActor20MoviesInfo
{
public int ActorID { get; set; }
public int FilmActorID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Count { get; set; }
}
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