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.
}