Entity Framework generates a code file for my database .edmx, it creates for each entity .. If I customize some properties (change column names, makes required properties ... etc) as example I have the following class that generated by EF and I added some codes for it :
public partial class person
{
public int Id { get; set; }
public string FullName { get; set; }
[Required(ErrorMessage = "Mother name is required!")]
[Column("Mother Name")]
public string MotherName { get; set; }
}
Each time I made changes on database and generate .edmx file again, all changes that I made are gone (as commented at the top of the file.)
I can add some new properties by adding a partial class as this solution says but I can't add a partial class that contain the same property.
My question is: How can I separate my custom code from .edmx to another file?
change column names, makes makes required propertiesthese things are specified by theedmxfile. That's where you should specify names and validations. The code generator will add the appropriate attributes to the generated propertiesCode-Firstseveral years ago, either generating classes directly from the database or generating tables from classes