Entity Framework Core Ignore Method

The Ignore method of the EF Core Fluent API is used to Ignore a Property or Entity (Table) from being mapped to the database

Consider the following Model. 

using System;

namespace EFCoreFluentAPI
{
  public class Employee
  {
    public int EmployeeID { get; set; }
    public string Name { get; set; }

    public DateTime DOB { get; set; }

    public int Age { get; set; }
  }

  public class TempTable
  {
    public int ID { get; set; }
    public string Name { get; set; }

  }
}

Ignore Property

The Age field in the Employee Class is redundant as we can always calculate it from the DOB property. Hence it is not required to be mapped to the database,

modelBuilder.Entity<Employee>()
            .Ignore("Age");

Ignore Entity

Similarly, we have TempTable, which we do not want to include in the database. You can use the Ignore method as shown below

modelBuilder.Ignore<TempTable>();

The following image shows the model and the database generated.

Data Annotation

The Ignore method is equivalent to NotMapped Attribute data annotation. There is no equivalent convention available

2 thoughts on “Entity Framework Core Ignore Method”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top