0
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.

1

1 Answer 1

3
private bedrijf_modelDataContext dc = new bedrijf_modelDataContext(); 

Creates a DataContext. Think of it as a workspace + database connection. It tracks the loaded entities.

var result = from a in dc.Afdelings select a; 

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'.

 return result.ToList(); 

The ToList() fetches all the records (counters the deferred execution).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.