I'm pretty new to this and my issue is very particular. I've googled a lot and haven't been able to find anything on this. I have two properties in a database, StartDate and StartMonth. The StartDate is of type DateTime and the StartMonth is of string type. (I know it's dumb to save both of these into the database but this isn't something I can change because I don't have the authority to do so.) My question is how in the DB Model can I set the StartMonth to equal the Month in the StartDate (since it is the same)? Rather, what is the proper way to do this? Any help is really appreciated!
To be clear I have currently:
[Table("EMPLOYMENT")]
public class Employment : EntityBase
{
[Column("STARTDATE")]
public DateTime? StartDate { get; set; }
[Column("STARTMONTH")]
public string StartMonth { get; set; }
}
EDIT: I tried the following (I realize it wasn't any of the suggested, but it was suggested by a co-worker):
[Table("EMPLOYMENT")]
public class Employment : EntityBase
{
[Column("STARTDATE")]
internal DateTime? StartDateInternal { get; set; }
[Column("STARTMONTH")]
private string StartMonth { get; set; }
[NotMapped]
public DateTime? StartDate
{
get
{
return StartDateInternal;
}
set
{
StartDateInternal = value;
StartMonth = value?.ToString("MMMM");
}
}
Specifically, the StartMonth is now private, the StartDate is now a NotMapped property that sets the StartDateInternal and StartMonth and returns the StartDateInternal value, and the original StartDate from the previous code is now named StartDateInternal. Though I can see that the value is being properly passed all the way to the model, it will not set the value. It always sets it to NULL in the database. I'm not sure why and was wondering if anyone could see why.