I have some LINQ to SQL classes that are single tables in the database (ie, I dragged and dropped the table from the SQL Server Object Browser to the DBML design layout window). I am considering filtering the table when I fill my view model observable collection like so: (commented out, but you get the idea):
class ObservableDocuments : ViewableCollection<Document>
{
public ObservableDocuments(DataClasses1DataContext dataDc)
{
foreach (Document doc in dataDc.Documents)//.Where(x => x.JobID == 1))
{
this.Add(doc);
}
}
}
I am wondering if this is an optimal way to handle this filtering. Does LINQ to SQL wait until this call before actually querying the database, or is the entire table still pulled in to the DataContext.Documents table, and then I am only adding the ones that I want to the ObservableCollection? If it is the latter, then is there a better way in LINQ to SQL to filter results, or should I move away from this framework?