I have this nasty problem: every time I want to update my Entity Framework (Database First) schema, I lose all the verification code that I wrote (with a resource for translation, etc.), and then I need to go back to to my previous code from version control and overwrite it as it was before the schema update. I found a patch to overcome this problem, but I find it rather overhead. I need some suggestions on how to probably handle this. So, let's say my model with validation and resources (in short for the question) looks like this:
public partial class tblReport
{
public int id { get; set; }
[Display(ResourceType = typeof(Resources.Admin), Name = "ReportName")]
[Required(ErrorMessageResourceType = typeof(Resources.Admin), ErrorMessageResourceName = "Required")]
public string reportName { get; set; }
[Display(ResourceType = typeof(Resources.Admin), Name = "CreatedDate")]
[Required(ErrorMessageResourceType = typeof(Resources.Admin), ErrorMessageResourceName = "Required")]
public DateTime dtCreated { get; set; }
}
After updating EF Schema, it will delete everything and return it to default, as shown below:
public partial class tblReport
{
public int id { get; set; }
public string reportName { get; set; }
public DateTime dtCreated { get; set; }
}
, , tblReport , 1 1 EF ... , :
public class tblReportModel : tblReport
{
public int id { get; set; }
[Display(ResourceType = typeof(Resources.Admin), Name = "ReportName")]
[Required(ErrorMessageResourceType = typeof(Resources.Admin), ErrorMessageResourceName = "Required")]
public string reportName { get; set; }
[Display(ResourceType = typeof(Resources.Admin), Name = "CreatedDate")]
[Required(ErrorMessageResourceType = typeof(Resources.Admin), ErrorMessageResourceName = "Required")]
public DateTime dtCreated { get; set; }
public tblReport ToTblReport()
{
tblReport tReport = new tblReport();
tReport.dtCreated = this.dtCreated;
tReport.reportName = this.reportName;
tReport.id = this.id;
return tReport;
}
public static tblReportModel ToTblReportModel(tblReport createdReport)
{
tblReportModel mReport = new tblReportModel();
mReport.dtCreated = createdReport.dtCreated;
mReport.reportName = createdReport.reportName;
mReport.id = createdReport.id;
return mReport;
}
}
, , , tblReportModel "/", . , ... , , ,
'IntranetApplication.Models.tblReportModel.dtCreated' hides inherited member 'IntranetApplication.Models.tblReport.dtCreated'. Use the new keyword if hiding was intended.
!!! - , ?