How to update column with GetUTCDate?

Posts   
 
    
RonENT
User
Posts: 28
Joined: 15-Oct-2012
# Posted on: 27-Oct-2012 02:19:19   

I'm trying to set a DateTime value column to the sql server side GetUTCDate() function's value. 1. How would this been done? (see ??? in code below) 2. Preferably, in one server trip for the Update only (as opposed to a separate Select trip).

_TestEntity entity=TestEntity(1); entity.Value="test"; entity.UpdateDate= ??? // GetUTCDate() entity.Save() _

Note: This has been discussed in other thread several years back; hopefully, by now it's possible or easier to implement.

Ron

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Oct-2012 06:36:00   

Hi Ron,

You can do it using UpdateMulti and expressions. The alternative is like this:

// trick to mark the field as changed and the entity as dirty
order.ShippedDate = DateTime.Now.AddYears(-10);

// set the expression you want to set
order.Fields[(int) OrderFieldIndex.ShippedDate].ExpressionToApply = 
    new DbFunctionCall("GetUTCDate", new object[] { });

Note that this will work only for updates, so no inserts supported. If you want it on inserts you must write your own triggers/default-values on the DB side.

David Elizondo | LLBLGen Support Team
RonENT
User
Posts: 28
Joined: 15-Oct-2012
# Posted on: 29-Oct-2012 18:19:39   

It Worked - Thanks, David.