使用linq插入服务器的时间 [英] Insert Time of server using linq

查看:75
本文介绍了使用linq插入服务器的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我有关在DB(SQL Server)中插入数据时如何插入服务器时间的问题.例如,如果我使用存储过程,我将使用GETDATE(),但是如何在LINQ中使用它呢?
thanx

Could anybody help me about how to Insert server time when I insert data in DB(SQL Server). for example if i use stored procedure I would use GETDATE() but how to do it in LINQ?
thanx

推荐答案

您可以将其添加到数据上下文中:
You can add this to your data context :
public partial class YourDataContext
{
  public DateTime GetDate()
  {
    return ExecuteQuery<DateTime>("SELECT GETDATE()").First();
  }
}



从这里提取:
http://stackoverflow.com/questions/200617/how-do-i-use-sqls-getdate-and-dateadd-in-a-linq-to-sql-expression [ http://social.msdn.microsoft.com /forums/zh-CN/linqprojectgeneral/thread/9204a37f-0d55-4b74-8906-0aed10019d38/ [



extracted from here :
http://stackoverflow.com/questions/200617/how-do-i-use-sqls-getdate-and-dateadd-in-a-linq-to-sql-expression[^]

Also have a look at this one :
http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/9204a37f-0d55-4b74-8906-0aed10019d38/[^]

Hope it helps.



这篇关于使用linq插入服务器的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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