Forse è notte inoltrata, ma sono qui perplesso. Sto cercando di combinare più elenchi con le stesse proprietà in uno solo. Pensavo che .UNION di LINQ avrebbe fatto il trucco ma mi ero sbagliato. Ecco un esempio di alcuni dei miei elenchi:C# - Combina più raccolte LINQ con le stesse proprietà
LIST1 (report names):
Date Name Title Product
02/01/13 Steve Hello World Report
02/05/13 Greg Howdy Report
LIST2 (song names):
Date Name Title Product
01/01/13 John Time Song
01/05/13 Bob Sorry Song
LIST3 (games names):
Date Name Title Product
12/01/12 Google Bike Race Game
12/05/12 Apple Temple Run Game
La mia classe è molto semplice. Ecco come si presenta:
public class MyClass {
public DateTime Date { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Product { get; set; }
}
Nel caso in cui vi state chiedendo, ho usato questa query LINQ per ottenere una delle liste di cui sopra:
var finalList = Games
.Select (s => new MyClass {
Date = (System.DateTime) s.Games.Creation_date,
Name = s.Games.Last_name,
Title = string.Format("{0} (Report)", s.Game.Headline),
Product="Report"
})
;
Finora, è abbastanza facile, ma voglio per unire tutte le mie liste in 1. Quindi, la mia lista finale dovrebbe essere simile:
Date Name Title Product
02/01/13 Steve Hello World Report
02/05/13 Greg Howdy Report
01/01/13 John Time Song
01/05/13 Bob Sorry Song
12/01/12 Google Bike Race Game
12/05/12 Apple Temple Run Game
ho pensato che un comando UNION lo farebbe:
var newList = List1.Union(List2).Union(List3);
Ma non sto ottenendo l'output desiderato.
Date Name Title Product
02/01/13 Steve Hello World Report
02/05/13 Greg Howdy Report
01/01/13 Bob Time Game
01/05/13 John Sorry Song
12/01/12 Google Bike Race Song
12/05/12 Apple Temple Run Game
Qualche idea su cosa sto facendo male qui?
ciò che vi risultato ottieni quando usi Union? –