I’m trying to figure out the best way to get the insertable and updateable columns and values on a class inside an orm lite filter. I basically need to loop over each column to insert its value into a table one row per column in both cases of insert and update. For an update I need to get the original record and then insert the original and new values into the same table.
Something like this:
public class AuditLogDetails
{
[PrimaryKey]
[AutoIncrement]
public int Id { get; set; }
public string ColumnName { get; set; }
public string OriginalValue { get; set; }
public string NewValue { get; set; }
public int AuditLogId { get; set; }
}
Filter code. How can loop over each row’s insertable/updatable properties to build the old and new values?
var queryType = row.GetType();
var modelDef = queryType.
var dialectProvider = dbCmd.GetDialectProvider();
var tableName = dialectProvider.NamingStrategy.GetTableName(modelDef);
var colNames = modelDef.GetColumnNames(dialectProvider);
var key = modelDef.GetPrimaryKey(row);
var existing = dbCmd.Connection.UnTypedSingleById(queryType, key);