Print Page | Close Window

Unit Of Work not returning newly created Entity

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4377
Printed Date: 10-Jun-2026 at 5:33am


Topic: Unit Of Work not returning newly created Entity
Posted By: gregweb
Subject: Unit Of Work not returning newly created Entity
Date Posted: 25-Sep-2013 at 4:48pm
When a new Item is added in Cocktail, a new unit of work is created and added to the UnitOfWorkManager:

_unitOfWork = UnitOfWorkManager.Create();
ContactEntity contactEntity = await unitOfWork.ContactFactory.CreateAsync();
UnitOfWorkManager.Add(contactEntity.Id, _unitOfWork);



Then later, when the DetailViewModel is Starting, it finds the correct UnitOfWork, and then retrieves the newly created entity:

ContactEntity = await UnitOfWork.ContactEntities.WithIdAsync(contactId);

The issue I am having is that the above line throws an error, as the entity is not found.

I have stepped through the code carefully, and it retrieves the UnitOfWork for the correct id (-100) but somehow the entity is not present. So I don't see what is going wrong.

The Factory.CreateAsync is creating the instance and adding it to the EntityManager, so it should be able to find it again.

Any idea what's going on?

Greg            



Replies:
Posted By: mgood
Date Posted: 25-Sep-2013 at 5:12pm
One thing to be aware of is that the UoWManager is a WeakDictionary, which means that unless something outside of the UoWManager is holding a reference to an item in the dictionary, the item will get garbage collected. The UoWManager will simply create a new UoW instance if the one with id -100 got garbage collected in the meantime, which is what you may be running into here. 


Posted By: gregweb
Date Posted: 25-Sep-2013 at 6:17pm
Thx Marcel, got this resolved.



Print Page | Close Window