The situation is as follows:
In a school where there is a certain class that is divided into 2 groups:
The First is studying English and the other one German, however the time allocated for the classes is the same.
I have the virtual situation where in the IList (holding a record from the DB) I have the same Time class for the same class of Students and I need to join these objects using C# and preferably LINQ.
In other words, I need to merge one object into another when these objects have the same Time property. The final result will be displayed in the school schedule (timetable) and the problem is to avoid having duplicated records.
I currently have something like:
var lessons = KlassLesson.GetKlassSchedule(userProfile.Preferences.MyClassID, dayOfWeek);
lessons = JoinDoubleLessons(lessons);
private List<KlassLesson> JoinDoubleLessons(List<KlassLesson> lessons)
{
// ?????
}
I should say that I’m not very clear about your question and since you’ve not answered my questions I’ve assumed that there is only one list and that this list contains some duplicate “AddedDate” values
The following is completely functional code. I set up a few lessons. Note that I’ve assigned two of these lessons the AddedDate value from the variable “testDateAndTime”. The Lessons with Titles
AAAAA
and
BBBBB
The output I get is:
Which shows two lessons (AAAAA and BBBBB) for the added date of 2/2/2011 3:24:36 AM
which is what I expect. But then again, I’m not sure what you’re expecting. I’m not sure about what you mean by “merge”. What you have with this solution is that duplicates have been identified (and grouped) so you can now take the duplicates and “merge” them any way you see fit.
You could modify the sql expression such that you get only the duplicates like so: