Example #1
0
        /// <summary>
        /// Automatically select all <see cref="CandidateKey"/> columns and their data values for specified <see cref="DataRow"/>.
        /// </summary>
        /// <param name="key">The <see cref="CandidateKey"/>.</param>
        /// <param name="dataRow">The specified <see cref="DataRow"/>.</param>
        /// <returns>Number of columns selected.</returns>
        public int AutoSelect(CandidateKey key, DataRow dataRow)
        {
            key.VerifyNotNull(nameof(key));
            dataRow.VerifyNotNull(nameof(dataRow));

            var valueKey = dataRow.Model.PrimaryKey;

            if (valueKey != null && valueKey.GetType() == key.GetType())
            {
                for (int i = 0; i < valueKey.Count; i++)
                {
                    _columnValues[key[i].Column] = valueKey[i].Column.GetValue(dataRow);
                }
                return(valueKey.Count);
            }

            var result       = 0;
            var valueColumns = dataRow.Model.Columns;

            foreach (var columnSort in key)
            {
                var keyColumn   = columnSort.Column;
                var valueColumn = valueColumns.AutoSelect(keyColumn);
                if (valueColumn != null)
                {
                    _columnValues[keyColumn] = valueColumn.GetValue(dataRow);
                    result++;
                }
            }
            return(result);
        }
Example #2
0
 internal KeyMapping(CandidateKey sourceKey, CandidateKey targetKey)
 {
     sourceKey.VerifyNotNull(nameof(sourceKey));
     targetKey.VerifyNotNull(nameof(targetKey));
     if (targetKey.GetType() != sourceKey.GetType())
         throw new ArgumentException(DiagnosticMessages.KeyMapping_SourceTargetTypeMismatch, nameof(targetKey));
     Debug.Assert(sourceKey.Count == targetKey.Count);
     _sourceKey = sourceKey;
     _targetKey = targetKey;
 }