Linq to Entities Group By
Bonjour !
J'ai simplement une requête Linq qui doit me renvoyer une liste d'entités par un Group By.
J'ai essayé cela :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
Dim liste as List(Of Saison)
liste = (From s In _db.Saisons
Group By s.ID, s.Debut, s.Fin, s.Libelle Into Group
Select New Saison With {
.ID = ID,
.Debut = Debut,
.Fin = Fin,
.Libelle = Libelle
}
).ToList |
Et là j'ai une exception :
Citation:
Le type d'entité « Saison » ne peut pas être construit dans une requête LINQ to Entities.
Ai-je une erreur de syntaxe ?
Résultat, je suis passé par 2 étapes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Dim query = From s In _db.Saisons
Group By s.ID, s.Debut, s.Fin, s.Libelle Into sais = Group
Select New With {
.ID = ID,
.Debut = Debut,
.Fin = Fin,
.Libelle = Libelle
}
Dim liste As New List(Of Saison)
For Each sais In query
liste.Add(New Saison With {
.ID = sais.ID,
.Debut = sais.Debut,
.Fin = sais.Fin,
.Libelle = sais.Libelle})
Next |
Mais je ne trouve pas très satisfaisant de devoir passer par un type anonyme, et de re-boucler pour créer toutes mes saisons...
Merci pour vos idées.