Reset PK field(s) to unassigned

Posts   
 
    
MatthewM
User
Posts: 78
Joined: 26-Jul-2006
# Posted on: 20-Sep-2006 23:31:29   

How can I do this without modifying template.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 21-Sep-2006 02:54:48   

Can you post what exactly you are wanting to do. A PK for an entity shouldn't be changed after it has been set.

MatthewM
User
Posts: 78
Joined: 26-Jul-2006
# Posted on: 21-Sep-2006 17:15:31   

bclubb wrote:

Can you post what exactly you are wanting to do. A PK for an entity shouldn't be changed after it has been set.

Yes, I understand. However, I have a case when cloning graphs via serialization that I need to reset the PK id to null/unassigned, and don't want to have to do:

newEntity.Fields = new EntityFields(); // ..whatever the correct syntax is
for (int f = 0; f < newEntity.Fields.Count; f++)
  if (!newEntity.Fields[f].IsPrimaryKey)
    newEntity.Fields[f].CurrentValue = this.Fields[f].CurrentValue;
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Sep-2006 03:00:39   

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=1834&HighLight=1 has a bit about this. Is your PK an identity/sequence? If so you should just have to set newEntity.IsNew = true and save.

MatthewM
User
Posts: 78
Joined: 26-Jul-2006
# Posted on: 25-Sep-2006 22:46:55   

bclubb wrote:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=1834&HighLight=1 has a bit about this. Is your PK an identity/sequence? If so you should just have to set newEntity.IsNew = true and save.

Yes that works for saving it..but i would like to be able to ask the entity what the current value is and get null instead of checking if it isNew first, which isn't that big a deal...just want it my way. wink

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Sep-2006 08:08:29   
myEntity.SetNewFieldValue((int)MyEntityFieldIndex.MyField, null);

To set a field to null, please use the above code. Also please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4986