Using EF Core 2.0, and I have a DateTimeSpan class with properties for Start and End. I'm using the type on two different properties in another entity. I configured that entity to use .OwnsOne() for both DateTimeSpan properties.
When I add migration, EF doesn't create fields for the owned entity properties.
```C#
public class DateTimeSpan
{
private DateTimeSpan()
{
}
private DateTimeSpan(DateTime start, DateTime end)
{
Start = start;
End = end;
}
public DateTime Start { get; }
public DateTime End { get; }
public TimeSpan TimeSpan => End - Start;
public static DateTimeSpan Create(DateTime start, DateTime end)
{
return new DateTimeSpan(start, end);
}
}
public class OtherEntity
{
public DateTimeSpan PickupWindow { get; set; }
public DateTimeSpan DeliveryWindow { get; set; }
}
modelBuilder.Entity
{
builder.OwnsOne(e=> e.PickupWindow);
builder.OwnsOne(e=> e.DeliveryWindow);
});
```
The resulting table does not have properties for PickupWindow.Start/End or DeliveryWindow.Start/End.
@footedr Read-only properties are not mapped by convention, so Start and End will not be mapped. Also, the compiler-generated backing field in this case is read-only. So to map these, either:
* Or declare an explicit backing field and then map the properties explicitly
```C#
private DateTime _start;
private DateTime _end;
public DateTime Start => _start;
public DateTime End => _end;
builder.OwnsOne(e => e.PickupWindow, b =>
{
b.Property(e => e.Start);
b.Property(e => e.End);
});
builder.OwnsOne(e => e.DeliveryWindow, b =>
{
b.Property(e => e.Start);
b.Property(e => e.End);
});
Most helpful comment
@footedr Read-only properties are not mapped by convention, so
StartandEndwill not be mapped. Also, the compiler-generated backing field in this case is read-only. So to map these, either:```C#
public DateTime Start { get; private set; }
public DateTime End { get; private set; }