-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Milestone
Description
Greetings, this is a question/feature request:
Per the Limitations section of the Value Conversions documentation: "There is currently no way to spread a conversion of one property to multiple columns or vice-versa."
Is something like this planned, or is there an alternative better way to do this?
I'm looking for a way to keep the backing fields out of my entity classes. And to not use strings in the configuration or public backing fields in my entity classes.
Here's a quick example from my current code working with a legacy DB:
From an entity class:
private DateTime _lastChanged { get; set; }
private int _lastChangedHour { get; set; }
private int _lastChangedMinute { get; set; }
public DateTime LastChanged
{
get
{
if (_lastChanged.Hour != 0 ||
_lastChanged.Minute != 0 ||
_lastChanged.Second != 0)
return _lastChanged;
var returnDateTime =
new DateTime(
_lastChanged.Year,
_lastChanged.Month,
_lastChanged.Day,
_lastChangedHour,
_lastChangedMinute,
0);
return returnDateTime;
}
set
{
_lastChangedHour = value.Hour;
_lastChangedMinute = value.Minute;
_lastChanged = value;
}
}From the entity's configuration:
builder.Ignore(o => o.LastChanged);
builder
.Property<DateTime>("_lastChanged")
.HasColumnName("SIST_ENDRET")
.HasColumnType("datetime")
.HasDefaultValue((DateTime) SqlDateTime.MinValue);
builder
.Property<int>("_lastChangedHour")
.HasColumnName("SIST_ENDRET_TIM")
.HasColumnType("decimal(2,0)")
.HasConversion<decimal>();
builder
.Property<int>("_lastChangedMinute")
.HasColumnName("SIST_ENDRET_MIN")
.HasColumnType("decimal(2,0)")
.HasConversion<decimal>();Thanks for your time!
Reactions are currently unavailable