views:

44

answers:

1

I saw this question (http://stackoverflow.com/questions/1888004/entity-framework-getutcdate): "Can I use the SQL-function getutcdate() from entity framework to set a date field in the database when saving an entity object?" with this answer from Craig Stuntz: "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."

Can somebody provide me a code snippet how to do this?

Thanks

A: 
var q = from e in MyContext.SomeEntities
        select new 
        {
           Entity = e,
           Utc = DateTime.UtcNow
        };

I just tried this in LINQPad; it works.

Craig Stuntz
Not exactly what I wanted. I mean an entity with a DateTime property and then some that will generate something like this sql: UPDATE Table1 SET SomeProp=@p1, DateProp=GETUTCDATE() WHERE ....
JaapM
Please feel free to ask the question you actually intended. I can't make heads or tails of your comment, and I believe I answered the question you *wrote.* In general, please do not expect anyone to put more effort into answering your questions than you put into writing them.
Craig Stuntz