> For the complete documentation index, see [llms.txt](https://raviram.gitbook.io/asp-module-2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raviram.gitbook.io/asp-module-2/display-movies/add-a-model.md).

# Add a model

## Add a model to an ASP.NET Core MVC app <a href="#part-4-add-a-model-to-an-aspnet-core-mvc-app" id="part-4-add-a-model-to-an-aspnet-core-mvc-app"></a>

In this topic, classes are added for managing movies in a collection. These classes are the "**M**odel" part of the **M**VC app.

These model classes can be used with any object-relational mapping (ORM) framework that simplifies the data access code that you have to write.

The model classes created are known as ***POCO*** classes, from **P**lain **O**ld **C**LR **O**bjects. POCO classes don't have any dependency on any ORM. They only define the properties of the data to be stored in the database.

### Add a data model class <a href="#add-a-data-model-class" id="add-a-data-model-class"></a>

Right-click the *Models* folder > **Add** > **Class**. Name the file `Movie.cs`

Update the `Models/Movie.cs` file with the following code:

```csharp
using System.ComponentModel.DataAnnotations;

namespace MvcMovie.Models;

public class Movie
{
    public int Id { get; set; }
    public string? Title { get; set; }
    [DataType(DataType.Date)]
    public DateTime ReleaseDate { get; set; }
    public string? Genre { get; set; }
    public decimal Price { get; set; }
}
```

#### What is this class about?

The `Movie` class contains an `Id` field, which is required by the database for the primary key.

The `DataType` attribute on `ReleaseDate` specifies the type of the data (`Date`). With this attribute:

* The user isn't required to enter time information in the date field.
* Only the date is displayed, not time information.

[DataAnnotations](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations) are covered in a later tutorial.

The question mark after `string` indicates that the property is nullable. For more information, see [Nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references)
