Search code examples
c#.netmodelframeworksentity

How to add attributes to entity framework model class without losing them after update database


I want to add attributes on properties inside my model class. But I know if I create new changes in database and update my model the attributes added will be removed. So my question is can I manipulate the model class into a POCO and reference the POCO instead of using EF model class when I do IQueryables.

public IQueryable<UserAccount> GetUserAccounts()
{
    return Entity.UserAccounts;
}

UserAccount is an auto generated template model class which was created by EF. Can I have my own model to have data annotations ?


Solution

  • Hy, The best approach is that you keep the autogenerated class as it is, which makes it more clean and extend class with a partial class containing the extra properties you want.