K13.0.95 I have a situation where the Columns of a DataQuery vary and cannot be explicitly set. The query joins tables with same-named columns, resulting in the error An item with the same key has already been added. due to the DataRecordContainer's constructor placing the field names of the IDataRecord into a Dictionary object.
An item with the same key has already been added.
DataRecordContainer
IDataRecord
Dictionary
Is there a way to get a handle on the DataRecord and remove the duplicate columns before the Query is resolved?
public DataRecordContainer(IDataRecord dataRecord) { this.dataRecord = dataRecord ?? throw new ArgumentNullException("dataRecord"); try { for (int i = 0; i < dataRecord.FieldCount; i++) { columnNameToIndex.Add(dataRecord.GetName(i), i); } } catch (ArgumentException innerException) { throw new InvalidOperationException("Duplicate column name(s): " + DumpColumnNames(dataRecord), innerException); } }
Before executing the DataQuery you can pre-process the query by handling the ExecuteQuery.Before event. For an example see Working with database queries in the API - Pre-processing queries in the documentation.
Thank you Marcel, this is an excellent option. After investigating the module's arguments, having only the QueryText to manipulate vs the full MDQ, I don't believe it to be a feasible option without some hairy string manipulation.
Please, sign in to be able to submit a new answer.