private bedrijf_modelDataContext dc = new bedrijf_modelDataContext();
public IList<Afdeling> selectAll()
{
var result = from a in dc.Afdelings
select a;
return result.ToList();
}
This code is supposed to return all the records from the Afdeling-table.
This code works, but it comes from my teacher, and there is no explanation whatsoever as to how this works. Can somebody explain what this exactly does? Thank you.
Creates a DataContext. Think of it as a workspace + database connection. It tracks the loaded entities.
Is a Linq query that retreives the records as objects. In this case everything from the table. The query is not executed immediately, Linq has ‘deferred execution’.
The ToList() fetches all the records (counters the deferred execution).