none
update with getdate() or SysDateTime() in entity framework RRS feed

  • Question

  • This question has been asked several times here on the forum but I didn't find a good solution untill now: 

    how can I obtain this using EF:

    update MyTable set DateLastUpdate=getdate() where ID=12345

    These proposed solutions don't work in my case:

    1. entity.DateLastUpdate=DateTime.Now + SaveChanges() => uses the client's datetime, not the servers datetime AND canonical functions seem to be used in queries only

    2. triggers : not database independant

    3. Default values and use of identity in de edmx: works only with insert, not update

    Anyone a solution ?

    Monday, February 20, 2012 3:36 PM

Answers

  • Not knowing what sort of application and architecture you are trying to implement I can only guess.  If the servers (which server?)datetime is what is important to you you will need to re-think your architecture and put a service of some type (wcf) in the middle.  Additionally, a trigger can be applied to inserts, updates, and deletes which will give you the time on the db server? 
    Tuesday, February 21, 2012 2:09 PM

All replies

  • Not knowing what sort of application and architecture you are trying to implement I can only guess.  If the servers (which server?)datetime is what is important to you you will need to re-think your architecture and put a service of some type (wcf) in the middle.  Additionally, a trigger can be applied to inserts, updates, and deletes which will give you the time on the db server? 
    Tuesday, February 21, 2012 2:09 PM
  • I agree with @buthfa, try to use service to get database datetime and call the service from client.


    Fighting like Allen Iverson. Neve give up!

    Thursday, February 23, 2012 6:50 AM