How to add extra property to the class in c# during using EF

1.7k views Asked by At

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".

1

There are 1 answers

0
Troopers On BEST ANSWER

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    
}