A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
Hi, @Andrej Čačala ,
The NotMapped attribute is still supported in .NET 5. It can be applied to properties of an entity class for which we do not want to create corresponding columns in the database. By default, EF creates a column for each property (must have get; & set;) in an entity class. The [NotMapped] attribute overrides this default convention. You can apply the [NotMapped] attribute on one or more properties for which you do NOT want to create a corresponding column in a database table.
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
[NotMapped]
public int Age { get; set; }
}
The above model maps to the database as shown below.
Alternatively you could try Ignore() :
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>().Ignore(m => m.Age );
base.OnModelCreating(modelBuilder);
}
If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Michael Wang