Predicate to zip two collections and use as binding source
I've got two collections, ObservableCollection<Lap> and a ObservableCollection<Racer> where Lap holds lap data of a car race and Racer, you guess it, the Racer's data. Both objects know the racerId.
Is there a way I can come up with a predicate to use that as a Zip-func to zip those two collections together? The reason I want to do that is to bind them DataGrid.
I had seen this, but can't quite see how to use it with a predicate.
I came up with that:
laps.Zip(participants, (lap, racer) => lap.EnrollmentId == racer.EnrollmentId);
But how would I map that to the D开发者_Python百科ataGridColumns?
I think you are looking for a Join instead, since you do want to combine the properties of both based on a matching Id. For Zip() to work both collections must have the same number of entries in the same matching order already.
var results = from racer in participants
join l in laps
on racer.EnrollmentId equals l.EnrollmentId
select new
{
//select the properties you are interested in here
//or just use both:
Racer = racer,
Lap = l
}
加载中,请稍侯......
精彩评论