I would like to dynamically add a mapping in a table script. It comes up often, but the situation I have today is to set the OrderSecret on an order if it's not already set. (I'll separately submit a feature request for the Ecom provider to do that automatically since it's a standard field).
I would like to not have to create a dummy mapping in the job for it, and rather, would like to create the mapping on the fly.
I thought I was getting close, but now the error I'm running into is "Column 'OrderSecret' does not belong to table EcomOrdersTempTableForBulkImport2.". So the AddMapping method seems to add the mapping, but it doesn't add the field to the temp table.
Here's the code I have so far:
var newSourceColumn = new Column("OrderSecret", typeof(System.String), mapping.SourceTable); var newDestinationColumn = new Column("OrderSecret", typeof(System.String), mapping.DestinationTable); mapping.AddColumnsFromSourceToMappingIfMissing = true; mapping.AddMapping(newSourceColumn, newDestinationColumn); mapping.GetColumnMappings().FirstOrDefault(c => c.DestinationColumn.Name == "OrderSecret").ScriptType = ScriptType.Constant;
I hoped that the AddColumnsFromSourceToMappingIfMissing property may cause it to be created, but that didn't seem to make a difference.
Since there is a AddMapping() method, I assume that it's possible to do.
Thanks,
Scott