Is there a way to map a DateTimeOffset
property to a SQL Server datetime
column, with the assumption that you can't change either side, meaning that the property and column have to stay those date types?
I know the easiest is to make them match but want to know if there's a way to work around this. I was looking into custom mappings but it seemed like I had to map all of the columns myself and not just the DateTimeOffset
property.
I tried:
modelBuilder.Entity<Customer>().Property(c => c.LastModifiedOn).HasColumnType("datetime");
But that threw the Member Mapping specified is not valid
error.
I was hoping to be able to put the UtcDateTime DateTimeOffset
property value in the DB and when reading have the DateTimeOffset
be in UTC (i.e. have an Offset of zero).