update object DatTime property automatically on Context.SaveChanges()

Thread is closed for posting
2 posts, 0 answers
  1. AndreaT
    AndreaT avatar
    27 posts
    Member since:
    Sep 2007

    Posted 22 Nov 2010 Link to this post


    I need to update a DateTime property only when an object is saved to database. This is a sort of timestamp fields that tells when last modification occurred and i would like to not use triggers to do this.
    Right now i handle it manually setting explicitly the DateTime.Now just before calling the context SaveChanges().

    It would be nice to have this handled automatically, that is having  the context to update that property just before (and only) when ctx.SaveChanges() occurs.

    Is There a way to do this?

    thank you
  2. Alexander
    Alexander avatar
    727 posts

    Posted 24 Nov 2010 Link to this post

    Hello AndreaT,

    This functionality is currently being implemented for the visual designer. We support this in the "classic" wizards but have not introduced it yet in the designer. This will happen in one of the following versions.
    At the moment you have two options, and it seems you have already found them:
     - Update the DateTime value on the server, by using a function like getdate() (for MSSql) and set the Kind of the DateTime property of the persistent class to PersistentReadOnly, so it does not get included in the insert statements generated by OpenAccess.
     - Set the DateTime value manually before calling SaveChanges().

    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Back to Top