4

I would like to extend my class which was generated by EF from database. I tried to do it using partial class:

public partial class Users
{    
    public bool IsOnline { get; set; } = false;       
}

I would like to populate my list of Users from database and by default set my extra property IsOnline to false - later this value will be changed.

The error occured when i tried to download data from DbSet. Something like:

Invalid column name "IsOnline".

boop_the_snoot
  • 3,209
  • 4
  • 33
  • 44
marmite
  • 113
  • 8
  • Please check this post in stackoverflow https://stackoverflow.com/questions/33378720/how-to-add-new-entity-properties-in-entity-framework-without-changing-database-m – Vivek Shah Aug 29 '17 at 07:44

1 Answers1

5

Add a NotMapped attribute on your property to flag your property as not used with entity framework

public partial class Users
{    
    [NotMapped]
    public bool IsOnline { get; set; } //by default a boolean property is always false    
}
Alin
  • 394
  • 5
  • 14
Troopers
  • 5,127
  • 1
  • 37
  • 64