New Posts New Posts RSS Feed: Duplicate Ids in UOW Manager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Duplicate Ids in UOW Manager

 Post Reply Post Reply
Author
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Topic: Duplicate Ids in UOW Manager
    Posted: 27-Sep-2013 at 6:54am
Thx, got this going.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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. 

Back to Top
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down