In WPF app I have an Observable Collection which is connected through databinding with ListView. I would like to populate this Observable Collection from LINQ to SQL query, but with no success. In fact my code even doesn't compile (I pointed out the problem lines with comments).
The structure of underlying Observable Collection Class is similar to the structure of SQL table from which I try to get a query.
Please, what's wrong with my approach?
Here is part of my code:
ObservableCollection<ShowsQu> _ShowQuCollection =
new ObservableCollection<ShowsQu>();
public ObservableCollection<ShowsQu> ShowQuCollection
{ get { return _ShowQuCollection; } }
public class ShowsQu
{
public string ShowCode { get; set; }
public DateTime Date { get; set; }
public TimeSpan Time { get; set; }
public string Description { get; set; }
}
private void VisualizeAllShows()
{
MyfirstdbDataContext context = new MyfirstdbDataContext();
_ShowQuCollection.Clear();
var sh = from p in context.Shows select p;
foreach (var p in sh)
_ShowCollection.Add(new ShowsQu
{
Date = sh.Date, //here is compile-time error
Time = sh.Time, //here is compile-time error
Description = sh.Description //here is compile-time error
});
}
}