什么是正确的SQL类型来存储净入库时间,其值> 24:00:00?正确、类型、时间、SQL

由网友(凉音)分享简介:我想存储的.Net 时间跨度在SQL Server 2008 R2。 I am trying to store a .Net TimeSpan in SQL server 2008 R2. EF code首先似乎在暗示它应该被存储为时间(7)在SQL。 EF Code First seems to be sugge...

我想存储的.Net 时间跨度在SQL Server 2008 R2。

I am trying to store a .Net TimeSpan in SQL server 2008 R2.

EF code首先似乎在暗示它应该被存储为时间(7)在SQL。

EF Code First seems to be suggesting it should be stored as a Time(7) in SQL.

然而时间跨度在.net中可以处理超过24小时更长的时间。

However TimeSpan in .Net can handle longer periods than 24 hours.

什么是处理在SQL服务器上存储的.Net 时间跨度最好的方法是什么?

What is the best way to handle storing .Net TimeSpan in SQL server?

推荐答案

我把它存储在数据库作为 BIGINT ,我会保存蜱数量(如: TimeSpan.Ticks 的属性)。

I'd store it in the database as a BIGINT and I'd store the number of ticks (eg. TimeSpan.Ticks property).

这样的话,如果我想获得一个TimeSpan对象,当我找回它,我可以做的TimeSpan.FromTicks(value)这将是容易的。

That way, if I wanted to get a TimeSpan object when I retrieve it, I could just do TimeSpan.FromTicks(value) which would be easy.

阅读全文

相关推荐

最新文章