I am trying to make a separate class with a LINQ query to use for binding to a WPF form. I have the code below that I have put together from the research on this site and others, but get a compile error stating.
Cannot implicitly convert type 'System.Linq.IQueryable' to system.Collections.ObjectModel.ObservableCollection'. An explicit conversion exists (are you missing a cast?)
Staff_Time_TBL
is a class that was autogenerated when making a LINQ to SQL. Staff_Time_TBL
is the name of a Table
in SQL Server which what I am trying to get data from.
class ObservableData
{
public ObservableCollection<Staff_Time_TBL> InfoData { get; set; }
public ObservableData(DatabaseDataContext database, int staffNo, DateTime fromDate, DateTime toDate)
{
InfoData = new ObservableCollection<Staff_Time_TBL>();
InfoData = database.Staff_Time_TBLs
.Where(staff => staff.Staff_No == staffNo &&
staff.Date_Data == fromDate &&
staff.Date_Data == toDate);
}
}
I tried to use Tolist()
but get this compile error,
Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.ObjectModel.ObservableCollection'
I hope I have be clear on what I am trying to do and any help as to What am I doing wrong?
Edit: This has more to do with implementing the Collection.