Entity Framework TimeSpan - Time Error

后端 未结 2 492
故里飘歌
故里飘歌 2020-12-18 07:34

I am using EF 5 and c#.

In my Main Project i use CodeFirst to Create my Database. There i got this Entity:

    public class Shift {
    public string         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-18 07:59

    Entity Framework version 5 doesn’t map timespan. But ou can use a workaround to use it anyway.

    Just store the timespan as TimeSpan for manipulation and as an Int64 for mapping

    public Int64 TimeSpanTicks{ get; set; }     
    [NotMapped]
    public TimeSpan TimeSpanValue
    {
        get { return TimeSpan.FromTicks(TimeSpanTicks); }
        set { TimeSpanTicks= value.Ticks; }
    }
    

提交回复
热议问题