简体   繁体   中英

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

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

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    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM