Print Page | Close Window

Duplicate Ids in UOW Manager

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=4379
Printed Date: 28-Apr-2024 at 5:27am


Topic: Duplicate Ids in UOW Manager
Posted By: gregweb
Subject: Duplicate Ids in UOW Manager
Date Posted: 26-Sep-2013 at 8:01pm
In an app, I use integer keys instead of Guids. So far this has worked fine. However, when creating new items, the new ID generated by DevForce is -100. This works the first time the user creates an item. However, if the user then saves that item, and creates another one, the id is again -100.

This doesn't work for the WeakRefDictionary as the former -100 is still there, so it throws a KeyIsAlreadyPresentInThisDictionary exception.

I am not sure of the best way to resolve this, but it seems to me I could update the WeakRefDictionary to remove the existing one if it found the same key already, instead of throwing an error.

Greg



Replies:
Posted By: mgood
Date Posted: 26-Sep-2013 at 8:21pm
Yes, this is highlighting a fundamental issue with database generated ids. They violate the fundamental principal of an entity, which says that the identity of an entity should never change. The data can change, but the entity shall maintain the same id. With database generated ids you are running into these kinds of issues. You can't uniquely identify new entities, because you don't know the permanent id until you save them. What you should do in this case is after you saved, you should remove the UoW from the dictionary and add it back with the permanent id. This is commonly referred to as id fixup. DevForce does this with the entities in the cache. It fixes up their ids after a successful save. 



Posted By: gregweb
Date Posted: 27-Sep-2013 at 6:54am
Thx, got this going.



Print Page | Close Window