I am trying to write a model for use within EF6 which includes a property that I would like to calculate in C# (not SQL). My model looks like this:
public class UploadRequestWorkingHours : UploadRequest
{
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public int WorkingHoursSinceResponseDate
{
get { return DateUtils.WorkingHoursSince(ResponseDate); }
private set { }
}
}
The UploadRequest
class contains the details, and this derived class introduces a property that should be calculated by LINQ/EF/whomever when the model is serialized.
Unfortunately, this property — WorkingHoursSinceResponseDate
— is making it into the database, even though I have marked the class as Computed
. I have also tried None
. I understand from reading the EF documentation that this DatabaseGeneratedOption
will still create a column in the database; I have been following posts such as this one that have lots of votes, but in reality, I don't think this is the solution.
How to I prevent a computed property in the model from making it into the DB? Another post suggests creating the migration and commenting out the field in the migration file created but this is very smelly and there's no way I'd get away with this!