Retrieving data with DbContext

chsakell's Blog

DbContext class is the one among others that the Entity Framework team has created, in order to facilitate developers when accessing and manipulating database data. In a nutshell, DbContext, DbSet, and DbQuery are the classes that have encapsulated the most frequently used patterns and functions while working with Entity Framework, replacing the old ObjectContext, ObjectSet and ObjectQuery respectively. In this post we will show how to use the DbContext class in order to retrieve data from database. We will use LINQ to Entities and LINQ to Objects queries to get data from database. Before continuing reading this post, if you are new either to Entity Framework or the LINQ I would strongly recommend you to read the related posts on this blog, Starting with Code First in Entity Framework and LINQ to Objects queries. Here’s what we are gonna look at this post:

  • Retrieve all data from a DbSet
  • Sort or…

View original post 839 more words