Models in ASP.NET

Learn about model classes in ASP.NET Core.

We'll cover the following

Model classes allow you to map data to your database. A model class usually consists of properties along with their “getter” and “setters”.

The number of model classes and types of properties in those model classes depends on your application requirements. For example, if your application is managing employee data, then your model classes could be Employee, Department, and Rank among others.

One of the most common model classes in any application is a User model class. In this lesson, examine a simple User model class in ASP.NET.


First, consider the properties your model class would require. Every model class requires a primary key. If you name a property as ID, Entity Framework will automatically detect it as a primary key. If you wish to name some other property as your primary key, you would need to use the [Key] attribute. There will be more on attributes later in the course.

Get hands-on with 1200+ tech skills courses.