Entity not being updated

Posts   
 
    
TallPaul
User
Posts: 2
Joined: 30-Oct-2007
# Posted on: 30-Oct-2007 19:05:39   

I am testing a datafile import process with something similar to the following using V2 of LLBLGenPro (Self Servicing) with VSTS 2005 against an Oracle v9 db.

When I use the AmendFields method then the updated values are visible in dbSystemEntity after the calls and around the save. The Boolean being returned by the Save comes back as true, but if I stick a commit on the transaction after the save then the revisions do not hit the db. If I haul the code out of AmendFields into the StoreTransferredEntity method and leave the code alone above and below where the AmendFields calls were, and again stick a commit after the save then it does its job as expected. I am sure that I have made a silly mistake but can't see where, hoping that a fresh pair of eyes will spot it.


        internal void StoreTransferredEntity(DataRow fileRow)
        {
            DAL.EntityClasses.SystemEntity dbSystemEntity = new DAL.EntityClasses.SystemEntity();

            if (dbSystemEntity.FetchUsingPK((Int64)fileRow["SysId"]))
            {
            }
            else
            {
                // Does not exist on the db.
                throw new DataException("System record received for a location that no longer exists on the centre db.");
            }

            AmendField(dbSystemEntity, "SysDbVersionText", fileRow);
            AmendField(dbSystemEntity, "SysSoftwareVersionText", fileRow);
            etc.

            _trans.Add(dbSystemEntity);
            dbSystemEntity.Save();
        }

        private void AmendField(IEntity ent, string fieldName, DataRow row)
        {
            if (!string.IsNullOrEmpty(row[fieldName].ToString()))
            {
                ent.Fields[fieldName].CurrentValue = row[fieldName].ToString();
            }
            else if (ent.Fields[fieldName].IsNullable)
            {
                ent.SetNewFieldValue(fieldName, null);
            }
            else
            {
                throw new NoNullAllowedException("Could not set " + fieldName + " to null");
            }

            // Plus variants of the above for the other data types.
        }


daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Oct-2007 01:20:30   

Hi TallPaul,

if (!string.IsNullOrEmpty(row[fieldName].ToString()))
{
     ent.Fields[fieldName].CurrentValue = row[fieldName].ToString();
}

Please try this:

if (!string.IsNullOrEmpty(row[fieldName].ToString()))
{
     ent.SetNewFieldValue(fieldName, row[fieldName].ToString());
}

Is recommended to use SetNewFieldValue, as this method set all the entity and field properties to indicate that the field value has been changed. If no change is detected the Save method will return _true _but without any effect at DB.

David Elizondo | LLBLGen Support Team
TallPaul
User
Posts: 2
Joined: 30-Oct-2007
# Posted on: 31-Oct-2007 10:46:11   

Works. The projects I have been on have only used SetNewValue for Nulling, so it didn't even register that it could be used in this occasion.

Many thanks. Paul.