I have an entity like:
public class EventItem
{
public int Id { get; set; }
public int Vn { get; set; }
public DateTimeOffset EventDate { get; set; }
...
}
..and then use EF fluent API to construct the db:
public class EventItemConfiguration : EntityTypeConfiguration<EventItem>
{
public CatalystItemConfiguration()
{
ToT开发者_如何学JAVAable("events");
HasKey(key => key.Id);
Property(item => item.Id).HasColumnName("event_id").HasColumnType("int");
Property(item => item.Vn).HasColumnName("event_vn").HasColumnType("int").IsRequired().IsConcurrencyToken();
Property(item => item.EventDate).HasColumnName("event_date").HasColumnType("datetimeoffset").IsRequired();
....
}
}
Now this all works when talking to SQL 2008. For testing I use SQL CE 4.0 and because Sql CE doesnt support datetimeoffset, the code above falls in a heap.
What are my options in getting this to work for Sql 2008 and Sql CE?
Save it in 2 separate fields, UtcEventDate and TimeZone:
public class EventItem
{
public int Id { get; set; }
public int Vn { get; set; }
public DateTime UtcEventDate { get; set; }
public string TimeZone { get; set; }
...
public DateTime GetLocalTime()
{
TimeZoneInfo tzInfo = TimeZoneInfo.FindSystemTimeZoneById(this.TimeZone);
return TimeZoneInfo.ConvertTimeFromUtc(this.UtcEventDate, tzInfo);
}
}
精彩评论