Our first application will create a database from code. We will start by creating an ASP.NET project that we will reuse in the following recipes.
Here we will create a Code First application and see the main concepts behind this technology and how to use it properly.
First open Visual Studio 2012 and create a new project. We will select the ASP.NET MVC 4 Web Application template from Visual C# | Web and name it
EFCodeFirst
as shown in the following screenshot:Select the Internet Application template as shown in the following screenshot:
Next, we will create a class that we will use as the schema to create a table. We will add the
BookModel
class to theModels
folder of our project as shown in the following code. Note that we will need to add a reference toSystem.ComponentModel.DataAnnotations.
namespace EFCodeFirst.Model { public class BookModel...