Question

I am new to EF. When I used DbContext Generator, it created separate partial classes for my entities. Next I added a property to one of the classes e.g. To the Users class I added a Phone property

 public partial class Users 
 { 
     public int UserId{get; set;} 
     /*new Property*/
     public int Phone{get; set;}
 }

But when I update the edmx, i.e. Update Model from Database, the new property is overwritten.

When I used Partial class instead of the DbContext Generator, the new property is not overwritten.

So what is the use of using Dbcontext generator then?

Was it helpful?

Solution

Because you generate your model from an existing database you are using the Database First approache.

If you want the Phone property to be created on your Users class then you must add a column name Phone in the associated table. After that you update your model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top