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 am a bit confused: I created a Window which itself creates always a new UnitOfWork. All Data are binded. When closing the Window I do a dispose on the UnitOfWork. So when I changed some entities and then i close the window without saving, nothing is saved into the database: that correct. But when reopening the window again (the new uow was created) i have the old values again. When closing the application and open the app again, the values are emtpy. in the constructor: this.UnitOfWork = ...DbContext.CreateUnitOfWork(); in the load method: // to get sure that the original is loaded again myDocument = this.UnitOfWork.FindOne<WpDocument>(myDocument); // get all values of document var documentValues = myDocument.myDocumentValues.Where(v => v.ContextId == contextId); with the above where clause, no sql is send to the database if i use this line, i get the correct values and a sql is send: this.UnitOfWork.Find<MyDocumentValue>(Entity.Attribute("MyDocumentId") == myDocument.Id && Entity.Attribute("ContextId") == contextId);
It seems that the where clause uses internaly cached values. By the way caching is always false. when closing the window the following is called: this.UnitOfWork.Dispose();
Is this a bug or did i misunderstand anything. Best regards Markus
|
|
|
It sounds like you are either inadvertently reusing the old unit of work, or you have second-level caching involved. I am a bit suspicious of this line: myDocument = this.UnitOfWork.FindOne<WpDocument>(myDocument); myDocument is meant to be an entity (a WpDocument) so passing it to FindOne doesn't really make sense. (FindOne needs an ID.) So I am wondering if perhaps myDocument is not getting reinitialised correctly, and therefore you are continuing to use the old myDocument instance (with the old unit of work). The reason your LINQ query does not send any SQL to the database is that the myDocument.myDocumentValues collection is already loaded (either because myDocument is an existing instance or because it is eager-loaded). Therefore there is no need to reload it from the database. In addition, because myDocumentValues has already been materialised as a List, the LINQ Where clause is evaluated using LINQ to Objects (i.e. on the client) rather than LINQ to LightSpeed (i.e. translated into SQL). Recent nightlies provide a means to do child collection queries on the database; let me know if this is what you need and I'll post the details, but this is usually relevant only if the collection could be extremely large. |
|
|
My first thought was that i am using the old unit of work, so i doublechecked, but no. I make a dispose when the window is closed and i create a new uow when opening the window. I also thought that the caching could be the problem, but all entities have set caching to false. About that line: myDocument = this.UnitOfWork.FindOne<MyDocument>(myDocument); MyDocument is an Entity. When i create the window the parameter myDocument as MyDocument is passed. A MyDocument Entity can have more MyDocumentValues. There is no eager loading enabled. First i attached myDocument to the new uow, but as i saw that i have old documentValues for it, i tried FindOne. Yes, it doesn't really make sense, what i wanted to do is, to get sure that i have a fresh loaded Entity. But myDocument is not really the Problem, but the myDocumentValues are the old ones when using myDocument.myDocumentValues. Could the problem be, that an entity is cross used between two uow? And when i am using myDocument.myDocumentValues the values are also saved in the other uow?
|
|
|
Some more details on my last researches: WpModelUnitOfWork UnitOfWork = ... CreateUnitOfWork(); var myDocument = UnitOfWork.FindOne<WpDocument>(Entity.Attribute("Id") == myDocument.Id); After the above line is executed, i am watching in the debugger: UnitOfWork.MyDocumentValues no result (correct) But at the same time: myDocument.MyDocumentValues has 13 new Entities (of the old and disposed UnitOfWork). Why could myDocument consists of 13 values whereas the whole uow has no MyDocumentValues.Count == 0? I am confused. |
|
|
The version of Mindscape.LightSpeed.dll is 2.2.1291.12179 and Mindscape.LightSpeed.Linq.dll has 2.2.1291.12179 |
|
|
Sorry for the delay in following up on this -- we have had some external commitments which have cut into support somewhat. We're not able to explain the behaviour you're seeing: I'm pretty sure there's some reuse of an entity or a UOW somewhere, but it's not clear where that might be without seeing the broader code context. Could you post a small but complete project (including SQL CREATE TABLE statements and ideally sample data) that reproduces the problem please, so that we can look into it? You can attach a zip file via the Options tab. Thanks! |
|
|
I will provide an example project in the next days. |
|