I have a list of custom objects called EntertainmentEvent:
public class EntertainmentEvent
{
public string Title { get; set; }
public string TagLine { get; set; }
public string Overview { get; set; }
public string ThumbnailUrl { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string EventTime { get; set; }
public Reoccurrence Reoccurrence { get; set; }
public string Url { get; set; }
}
I’d like to merge items with the same StartDate together into a single EntertainmentEvent which has a title of the two merged items concatenated together.
So far I have this:
var duplicateDates = allEvents.Join
(
allEvents, x => x.StartDate, y => y.StartDate,
(x, y) => x.Title != y.Title
? new EntertainmentEvent
{
Title = string.Format("{0}, {1}", x.Title, y.Title),
StartDate = x.StartDate
}
: null
)
.Where(x => x != null)
.ToList();
The only problem with this method is that I get duplicated items – for a sinlge date , duplicateDates list will end up with two entries
Entry 1: Startdate = 1/1/2011, Title = “Item One Title, Item Two Title”
Entry 2: Startdate = 1/1/2011, Title = “Item Two Title, Item One Title”
I’m certain there’s a better way of coding this but research has come up empty thus far.
Thanks 🙂
1 Answer