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
|
Hi, I am storing a User object in the session which is an Entity<int> subclass. However when I update information on the object, after retrieving it from the session, it is not updating the Database. Is there some limitation with lightspeed that prevents it from being stored like this and then updated at a later stage? Thanks, Craig |
|
|
Entity instances are associated with a unit of work, and a unit of work typically lives only for the duration of a request. So when you retrieve your User object in a subsequent request, it is not associated with the current unit of work, but with an old one: the current UOW doesn't know about the User object. When you call SaveChanges on the current UOW, it saves the entities it knows about, but the User isn't on that list. One approach to this is to attach the retrieved User object to the current request's unit of work using IUnitOfWork.Attach(), though this has potential concurrency issues if the user is making multiple requests at the same time. A probably better approach is to store the user ID in session, rather than the user object, and retrieve it on each request. You can use caching (see Help Topics > LightSpeed > Caching in the help file) to avoid the database hit if performance is critical in this case. |
|