Problem Saving

Posts   
 
    
Sean_22
User
Posts: 5
Joined: 15-Mar-2005
# Posted on: 16-Mar-2005 20:23:48   

Hi again,

I wrote yesterday regarding accessing multiple databases for "syncing" and have a new, small problem with saving. When I execute the following code:

foreach (POS_WkstnEntity entityToImport in toMoveCollection) { POS_WkstnEntity newRemoteEntity = new POS_WkstnEntity();

for (int i = 0; i < entityToImport.Fields.Count; i++) { newRemoteEntity.Fields[i].CurrentValue = entityToImport.Fields[i].CurrentValue; } newRemoteEntity.Save(); }

(where toMoveCollection is, obviously, a llblgen collection of my POS_Wkstn table)

for some reason my newly created and populated entity will not save into the database. I've put a break on the .Save() and examined the entity object and all the fields are correctly filled in, but the record wont appear in the DB. However, if, just prior to the .Save() call I throw in a line assigning a value in the newly created entity by name (eg newRemoteEntity.WTN_Name = "WTN1") the code works fine (ie ALL of the fields are populated and everything is peachy within the DB). Since I plan to abstract this entire method to allow me to simply pass in a table name rather than rewriting the same method for EVERY table I need to do this copy for, assigning even a single field by name is not pausable.

What am I missing?

Sean_22
User
Posts: 5
Joined: 15-Mar-2005
# Posted on: 16-Mar-2005 20:30:05   

Nevermind, just noticed that the IsDirty value isnt set via setting the field values directly as I was in the for loop.

Added a line to flag the entity as dirty just before the save and all is well.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-Mar-2005 20:43:02   

yes setting the current value directly is not making the entity see the changed field. If possible, use entity.SetNewFieldValue() simple_smile

Frans Bouma | Lead developer LLBLGen Pro