This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I a recent nightly you added the options "Track creation time" and "Track update time". It would be really nice if you could add a feature to also track the usernames (operating system). Or: Can this be achieved by an existing feature? We are also interested in a feature to count the changes in a "version" column. |
|
|
There isn't a built-in feature for tracking users, because many applications have their own user IDs instead of the OS username, and LightSpeed doesn't know what user model is in use. (Non-OS user models are certainly not an obscure edge case -- for example, almost all Web applications use their own user model instead of the OS one.) However, you can implement this by overriding Entity.OnSaving and modifying the appropriate field (don't forget to call the base class implementation when you're done). You can determine whether the entity is being created, updated or deleted by examining the EntityState property. The Optimistic Concurrency Checking option adds a LockVersion field which can be treated as a version counter, though this is an implementation detail of the concurrency checking strategy, and technically shouldn't be relied on. You could of course use the same OnSaving trick to populate your own Version column. |
|
|
Is there a way to react on save on a UnitOfWork level? We have a 120+ class Model and I do not want to add this functionality to each of the classes. It also carries a rist of missing one class. |
|
|
Not directly. But if you are using a strong-typed (LINQ) unit of work, then you can override UnitOfWork.SaveChanges -- you just need to make sure you always create instances of your derived UOW type rather than the base UOW type. Your override can enumerate all entities (UnitOfWork is IEnumerable<Entity>), update New and Modified ones as required, and then call the base class implementation. |
|