For information about the tutorial series, see the first tutorial in the series.
In the previous tutorial you implemented table-per-hierarchy inheritance.
Implementing these patterns can help insulate your application from changes in the data store and can facilitate automated unit testing or test-driven development (TDD).
However, writing additional code to implement these patterns is not always the best choice for applications that use EF, for several reasons: For more information about how to implement the repository and unit of work patterns, see the Entity Framework 5 version of this tutorial series.
In an earlier tutorial you saw how to do that in interceptor code; now you'll see some ways to do it without writing interceptor code.
To try this out, you'll look at a simple query and then look at what happens to it as you add options such eager loading, filtering, and sorting.
The code that does this in Suppose you want to write the code that retrieves this data directly in SQL rather than using LINQ. If the university has a large number of courses, it would be inefficient to retrieve them all as entities and change them individually.
To do that you need to run a query that returns something other than entity objects, which means you need to use the Database. In this section you'll implement a web page that enables the user to specify a factor by which to change the number of credits for all courses, and you'll make the change by executing a SQL ). You see the number of rows affected: Click Back to List to see the list of courses with the revised number of credits.
For example, see the following two debugger images.This version of the tutorial doesn't set the Modified flag on a model-binder-created entity in the Edit method, so it doesn't need .Sometimes it's helpful to be able to see the actual SQL queries that are sent to the database.This tutorial includes introduces several topics that are useful to be aware of when you go beyond the basics of developing ASP.NET web applications that use Entity Framework Code First.You'll sort the courses by title, and you'll specify eager loading for the With the breakpoint still set, run the Course Index page.Continue through the first times that the code hits a breakpoint, so that the page is displayed in the browser.You can disable tracking of entity objects in memory by using the As No Tracking method.Typical scenarios in which you might want to do that include the following: For an example that demonstrates how to use the As No Tracking method, see the earlier version of this tutorial.The Contoso University sample web application demonstrates how to create ASP.NET MVC 5 applications using the Entity Framework 6 Code First and Visual Studio 2013.One way to do that is to use parameterized queries to make sure that strings submitted by a web page can't be interpreted as SQL commands.In this tutorial you'll use parameterized queries when integrating user input into a query.Many developers write code to implement the repository and unit of work patterns as a wrapper around code that works with the Entity Framework.