Use of Time with EF 6

4

I have a class with the following property.

  public TimeSpan TempoIdeal { get; set; }

Estou atribuindo esta propriedade com 

TempoIdeal = new TimeSpan(days: 3, hours: 15, minutes:10, seconds: 0);
 

When trying to insert I get this error Overflow

  

SqlDbType.Time. The value '3.03: 03: 00' is out of range. He must   be between 00: 00: 00.00 and 23: 59: 59.9999999.

In SQL this property is being mapped as Time (7);

I'm using EF 6 with ASP.NET 4.52

    
asked by anonymous 23.06.2016 / 05:39

1 answer

3

Berechit, type Time no Sql-Server was not designed to store time intervals, or relative time (as in its example: the product took 3 dias, 15 horas e 10 minutos to be delivered), but to store an exact time as in your example: the product will be delivered with 15:10 ).

In this way, it does not make sense to store values greater than 23:59:59.9999999 . So if you really need to store values greater than '24 hours% with% BigInt% with% Sql-Server 'and do the following mapping.

public Int64 TempoIdealTicks { get; set; }

[NotMapped]
public TimeSpan TempoIdeal
{
    get { return TimeSpan.FromTicks(this.TempoIdealTicks); }
    set { this.TempoIdealTicks = value.Ticks; }
}
    
23.06.2016 / 13:51