Reputation: 10865
What's the best way to populate a collection with multiple data?
var query = (from p in obsDay where p.courseFaculty == "abellana" select p);
foreach (var item in query)
{
facultyTime.Add(
new TimePerDay()
{ subjTime =
new ObservableCollection<TimeSpan>
{ item.courseTimeStart }
}
);
}
availProf[randomNumber].actualTime = facultyTime;
I tried this one but it only adds one data on my collection? What am I doing wrong?
Upvotes: 0
Views: 322
Reputation: 21108
Your query object probably only contains 1 item. try stepping through it with your debugger.
Upvotes: 0
Reputation: 12624
actualTime
gets set as the facultyTime. Which is constantly getting Add
ed to? I'd guess it's either something in the Add method, or something in the actualTime property setter that isn't going through the whole facultyTime collection (if indeed it is a collection). Some clarity on what these objects are would be helpful in determining the issue.
Upvotes: 0
Reputation: 7358
You should run the query from LinqPad to make sure that your data actually matches your expectations. Your foreach loop is fine, your query is only returning one result, which makes it a data issue.
Upvotes: 1