1

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()
        {
            ToTable("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?

ozczecho
  • 8,649
  • 8
  • 36
  • 42

1 Answers1

2

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);
    }
}

David Wick
  • 7,055
  • 2
  • 36
  • 38
  • Fair enough, a valid option. Wondering if there are any other options. – ozczecho Apr 20 '11 at 08:47
  • There's always SQL Express instead of CE. I was going to suggest creating a custom CLR type for CE but come to find out that also isn't support. – David Wick Apr 20 '11 at 21:55
  • 1
    :-)...I was trying to use Sql CE for its low impact (ie no install required). But am quickly finding out its tight limitations. – ozczecho Apr 21 '11 at 01:34