I'm having troubles reaching this goal: I have a entity called ApplicationUser that I want to save to a static property in my businesslayer so that I allways know wich user is authenticated. When I create the domain the currently logged in user is saved to this property, but when the session ends and the next time I create a new Session and try to persist another entity (say Appointment) I want to do this:
The application throws an exception that the operation is not permitted because the ApplicationUser is created in a different Session (duh... :P). My question is how I can save a entity so that I can bind them later on to the currently active Session. I know it should be something with the DisconnectedState, but I can't figure it out... Updated at 22.06.2010 10:10:29
Thanks for the explanation! This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by stefmen. |
Save either its Key by the code like this:
Or use Ref<t> type - a nice wrapper for such tasks:
stefmen wrote: Thank you! This was also my 'workaround' solution, because now everytime the authenticateduser is requested DO 4.x has a roundtrip to the database? Or am I wrong? No, roundtrip will happen just once per each transaction (i.e. exactly when necessary). Query.SingleOrDefault checks the cache first. Well, that's our own method, so that was easy ;) |