什么是正确的SQL类型来存储净入库时间,其值> 24:00:00? [英] What is the correct SQL type to store a .Net Timespan with values > 24:00:00?

查看:240
本文介绍了什么是正确的SQL类型来存储净入库时间,其值> 24:00:00?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储的.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对象,当我找回它,我可以做的<一个href="http://msdn.microsoft.com/en-us/library/system.timespan.fromticks.aspx">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.

这篇关于什么是正确的SQL类型来存储净入库时间,其值&GT; 24:00:00?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆