In my domain model I have a property type Property<T>
which holds a Value and a DefaultValue just beside:
public class Property<T> : Entity
{
public Property(T defaultValue)
{
DefaultValue = defaultValue;
Value = defaultValue;
}
public T DefaultValue { get; }
public T Value { get; set; }
}
I like to use the default initialization to have the default value set when using that property type:
public class Device : Entity<Guid>
{
public Property<double> Calibration { get; } = new Property<double>(5.0);
}
I want to save Value for the Calibration property in the database using EF Core and I also want keep the DefaultValue as it comes from the default initialization.
Question: do I need to save also DefaultValue in the database or can I tell EF Core somehow to use it from the default constructed object when doing the Get() call on the repository for entity type Device?
This would save me the "effort" to store the complete Property as an entity in the database when only Value needs to be stored (and the DefaultValue comes by the type definition). Using a ValueConverter to save only the Value of the Calibration property would be fine for that.
Before I had the domain objects mapped to entities but now I try to merge them to get rid of the automapping step in between.