Hello. At my domains for audit purposes I've got UpdatedOn property. Now I set it at client before updating to DateTime.Now. But a lot of users have incorrect datetime at theirs machines, so i need use server datetime (getdate(),now()...) How can i implement this strategy?
I'm going to suggest this http://mastercsharp.com/article.aspx?ArticleID=66&TopicID=7 for you since this might be what you're looking for. Or you could just create a webservice to return the server time...
You can make this property a read-only/query only property and so ignore application code entirely. Just set a default value on insert of a row
CREATE TABLE [dbo].[FooTable](
.
.
.
[UpdatedOn] [datetime] NOT NULL CONSTRAINT [DF_FooTable_UpdatedOn] DEFAULT (Getdate()),
.
.
this will ensure that when a value is not passed then the column will take the value of Getdate()
In our project, we customized our MsSql2005Dialect.
public class MsSql2005Dialect : NHibernate.Dialect.MsSql2005Dialect
{
public MsSql2005Dialect()
{
RegisterFunction("getDate",
new NoArgSQLFunction("convert(datetime, floor(convert(float, getdate())))", NHibernateUtil.DateTime, false));
RegisterFunction("getDateTime",
new NoArgSQLFunction("getdate", NHibernateUtil.DateTime, true));
}
}
and we register this custom dialect in nhibernatehelper: Dialect dialect = Dialect.GetDialect(configuration.Properties);
register in the hibernate.cfg.xml: SAGP.DataAccess.Dialects.MsSql2005Dialect, SAGP.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
and use this in hql like: "select getDateTime() from RandomTableFromYourSystem";