O'Reilly logo

Code-First Development with Entity Framework by Sergey Barskiy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a new database based on .NET classes

When it comes to working with data, we will need to create at least two types of classes. We need to create one or more classes to map the tables in the database, where each class represents a row of data in the corresponding table. You also need at least one class that represents the database itself, which will inherit from DbContext. To start with, let's create a class with the same structure as the Person table from the Chapter 1, Introducing Entity Framework, with properties for id and the first and last names. Here is how the class looks in C#:

public class Person
{
    public int PersonId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Tip

Downloading the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required