Is there a way to assign a value to a not mapped property after all mapped properties get their values from the DB? For example:
public class ProcessSupervisor
{
public int ID { get; set; }
public int MaximumConcurrentProcesses { get; set; }
[NotMapped]
public int AvailableProcessSlots { get; set; }
}
I would like to keep the value of MaximumConcurrentProcesses
in the database and assign that value to AvailableProcessSlots
as a default value once Entity Framework instantiates ProcessSupervisor
DBSet and assigns corresponding values to objects properties. Obviously I cannot assign the value of MaximumConcurrentProcesses
to AvailableProcessSlots
in class constructor since MaximumConcurrentProcesses
hasn't received it's value from database yet. Is there a proper way do do it without initializing the AvailableProcessSlots
value in some weird and awkward way?
You can try something like this:
public class ProcessSupervisor
{
public int ID { get; set; }
public int MaximumConcurrentProcesses { get; set; }
[NotMapped]
private int? availableProcessSlots = null;
public int AvailableProcessSlots
{
get
{
return availableProcessSlots ?? MaximumConcurrentProcesses;
}
set
{
availableProcessSlots = value;
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments