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
|
Hello again, i get the following Exception if i want to find out what Entities are modified: Query Error: Could not find field [EntityState] on model [WpDocument] Here is the code: var modifiedDocs = unitOfWork.Documents.Where<Document>(doc => doc.EntityState != EntityState.Default); ...
When i use the following code then it works: foreach (var item in unitOfWork.Documents) { ... } I don't understand why. I use my workaround, but i am curious :)
Thanks Markus |
|
|
Hi Markus, This is because EntityState is not a database value - it simply reflects the state of the object once it's in memory. You'll want to be careful here because you're effectively pulling all the rows that AREN'T loaded, into memory as part of your check. You could write this: unitOfWork.Documents.ToList().Where<Document>(doc => doc.EntityState != EntityState.Default); The ToList() would load all objects into memory and the LINQ query would be executed with LINQ to Objects (not LightSpeed) and therefore it could inspect the properties that aren't from the database. Why are you needing to check which entities have been modified out of interest? There may be a better way to achieve what you're trying to do :-) I hope that helps, John-Daniel Trask |
|
|
Hi John-Daniel, ok .ToList() works fine. But you are right, that i have to be careful because everthing has been loaded into memory. The reason why i am doing this - good question :) - i didn't know a better way. Let me explain what i trying to do: I have a db table named "DefaultDocuments" which includes the field "Name" and the table "Documents" which also includes "Name". I create a page which lists all (default) documents and the user can change the name of his document if he want. If the "Name" of Documents is String.Empty then the Default Name is used. The textboxes are binded to the DocumentName and if this is emtpy i set the document name to the default name. Now when the user clicks on save, i check if the name of the document is the same as the name of the default on. If so, then i will save String.Empty. Hope i explained well :) Maybe there is a better way and it would be nice if you can give me a hint. Thanks Markus |
|
|
Hi Markus, It sounds like you probably want to be performing your query over the in-memory collection of default documents (or loaded documents?). (By constrast, unitOfWork.Documents represents all documents in the database.) So presumably you have an IList<DefaultDocument> which is what your repeater or whatever is bound to. If so, you can use LINQ to Objects to query over that list, e.g. defaultDocuments.Where(dd => dd.Name == dd.Document.Name) or defaultDocuments.Where(dd => dd.Document.EntityState != EntityState.Default) |
|