Hi,
Can I use the SQL-function getutcdate() from entity framework to set a date field in the database when saving an entity object?
regards Freddy
Hi,
Can I use the SQL-function getutcdate() from entity framework to set a date field in the database when saving an entity object?
regards Freddy
You can't map directly to SQL built-in functions, but you can make EF calls to user-defined functions. Write a function that just returns GETUTCDATE()
, then map to your user-defined function. I've done this before with SOUNDEX()
(needed to select by soundex), and it worked out very nicely.
Why wouldn't you set the property on the entity to the UTC date before saving it?
Alternatively you could use stored procedures for insert/update/delete of your entities. The stored procedure could perform this.
Yes, you can do this. The CLR function DateTime.UtcNow
is mapped to the canonical function CurrentUtcDateTime
, which should translate, for SQL Server to GETUTCDATE()
or similar.