This is a migrated thread and some comments may be shown as answers.

update object DatTime property automatically on Context.SaveChanges()

1 Answer 67 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AndreaT
Top achievements
Rank 1
AndreaT asked on 22 Nov 2010, 01:54 PM
Hi,

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
AndreaT

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 24 Nov 2010, 04:04 PM
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().

Regards,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
Getting Started
Asked by
AndreaT
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or