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, using the DistributedExample, I have created and saved a Story with two Comments and then performed several tests to see what happens with references to the same entities. First test. If I do this: story = unitOfWork.Find<Story>().First(); var comment = unitOfWork.Comments.Where(c => c.StoryId == story.Id).First(); story.Comments.Remove(comment); story.Comments continues to have 2 elements, the comment was not removed from the collection. But if I do: story = unitOfWork.Find<Story>().First();
story.Comments.Remove(story.Comments[0]);
The comment is removed from story.Comments. But both pieces of code do the same ideally, although the results are not. Second test, adding new entities. If I do this: var story1 = unitOfWork.Find<Story>().First(); story1.Comments.Add(new Comment() { ... }); unitOfWork.SaveChanges(); The comment added to story1 is saved to the database. But if I do this: var story1 = unitOfWork.Find<Story>().First(); var story2 = unitOfWork.Find<Story>().First(); story1.Comments.Add(new Comment() { ... }); unitOfWork.SaveChanges(); The comment added to story1 is NOT saved to the DB. But if I do this:
var story1 = unitOfWork.Find<Story>().First(); var story2 = unitOfWork.Find<Story>().First(); story2.Comments.Add(new Comment() { ... }); unitOfWork.SaveChanges();
The comment of story2 is saved to the DB. And even if I do SaveChanges(true), if after the save I ask for the Count of Comments on story1 and story2, they are different but I would expect them to be the same (if the UoW map is reset, then it has to query again to get that number, no?). Regards, Vicente |
|
|
Thanks for reporting this! There was an issue with entities not being returned from the identity map with certain types of queries which was the case with what you were seeing in the situations. I have added in a fix for tonights nightly build. Just in case this hasnt covered all the cases please let us know if you continuing seeing any of these problems after updating.
Jeremy
|
|
|
Hi Jeremy, I have tried the latest nightly, and the second case is solved, but the first one continues to fail. Regards! Vicente |
|