/// <summary> /// Builds key mappings between source model and target <see cref="KeyOutput"/> model. /// </summary> /// <param name="mapper">The column mapper.</param> /// <param name="source">The source model.</param> /// <param name="target">The target <see cref="KeyOutput"/> model.</param> public static void BuildKeyMappings(ColumnMapper mapper, Model source, KeyOutput target) { var sourceKey = source.PrimaryKey; if (sourceKey == null) { throw new InvalidOperationException(DiagnosticMessages.DbTable_NoPrimaryKey(source)); } var targetKey = target.PrimaryKey; if (targetKey == null) { throw new InvalidOperationException(DiagnosticMessages.DbTable_NoPrimaryKey(target)); } if (targetKey.Count != sourceKey.Count) { throw new InvalidOperationException(DiagnosticMessages.DbTable_GetKeyMappings_CannotMatch); } for (int i = 0; i < targetKey.Count; i++) { var targetColumn = targetKey[i].Column; var sourceColumn = sourceKey[i].Column; if (targetColumn.DataType != sourceColumn.DataType) { throw new InvalidOperationException(DiagnosticMessages.DbTable_GetKeyMappings_CannotMatch); } mapper.Select(sourceColumn, i); } }