How do I map TimeSpan with greater than 24 hours to SQL server Code First?

后端 未结 3 707
自闭症患者
自闭症患者 2020-12-29 01:34

I am trying to map a TimeSpan Code First property to SQL server. Code First seems to be creating it as a Time(7) in SQL. However TimeSpan in .Net can handle longer periods t

3条回答
  •  悲哀的现实
    2020-12-29 02:32

    First of all, MVC has nothing to do with this issue. It is entirely related to EF Code First and SQL Server so it's a DAL matter.

    One solution could be to provide a custom column type in your entity configuration, like this:

    modelBuilder
    .Entity()
    .Property(c => c.MyTimeSpan)
    .HasColumnType("whatever sql type you want to use");
    

提交回复
热议问题