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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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,
1 2 3 4 | 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
1 2 3 | 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
+1000 prro
Thanks