Creating a non mapped property in an entity (entity framework)

前端 未结 4 2088
[愿得一人]
[愿得一人] 2020-12-09 07:32

I want to create a custom property on one of my entities mapped from the database, however this property is not mapped to the database, I created the property using partial

4条回答
  •  攒了一身酷
    2020-12-09 08:03

    You can also mark your property with [NotMapped] attribute or use Ignore method from fluent API.

    Property

    public class EntityName
    {
        [NotMapped]
        private string PropertyName { get; }
    }
    

    Fluent API

     public class Entities : DbContext
     {
        public DbSet Users { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
           // Some database configuration
           modelBuilder.Entity()
                 .Ignore(i => i.PropertyName);
         }
     }
    

提交回复
热议问题