コード例 #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);
        }
コード例 #2
0
ファイル: KeyMapping.cs プロジェクト: aTiKhan/RDO.Net
 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;
 }
コード例 #3
0
 /// <summary>
 /// Determines whether all columns of specified <see cref="CandidateKey"/> are contained in this dictionary.
 /// </summary>
 /// <param name="key">The specified <see cref="CandidateKey"/>.</param>
 /// <returns><see langword="true" /> if all columns of specified <see cref="CandidateKey"/> are contained in this dictionary,
 /// otherwise <see langword="false" />.</returns>
 public bool ContainsKey(CandidateKey key)
 {
     for (int i = 0; i < key.Count; i++)
     {
         var column = key[i].Column;
         if (!ContainsKey(column))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #4
0
ファイル: CandidateKey.cs プロジェクト: xydoublez/RDO.Net
        /// <summary>
        /// Join with target candidate key.
        /// </summary>
        /// <param name="target">The target candidate key.</param>
        /// <returns>Column mappings between this candidate key and the target candidate key.</returns>
        /// <remarks>You must ensure these two canidate key objects have identical columns, otherwise an exception will be thrown.</remarks>
        public IReadOnlyList <ColumnMapping> UnsafeJoin(CandidateKey target)
        {
            target.VerifyNotNull(nameof(target));
            if (Count != target.Count)
            {
                throw new ArgumentException(DiagnosticMessages.PrimaryKey_Join_ColumnsCountMismatch, nameof(target));
            }

            var result = new ColumnMapping[Count];

            for (int i = 0; i < Count; i++)
            {
                var sourceColumn = this[i].Column;
                var targetColumn = target[i].Column;
                if (sourceColumn.DataType != targetColumn.DataType)
                {
                    throw new ArgumentException(DiagnosticMessages.PrimaryKey_Join_ColumnDataTypeMismatch, string.Format("{0}[{1}]", nameof(target), i));
                }
                result[i] = new ColumnMapping(sourceColumn, targetColumn);
            }

            return(result);
        }
コード例 #5
0
ファイル: DbTableDelete.cs プロジェクト: aTiKhan/RDO.Net
 public static async Task <int> ExecuteAsync <TSource>(DbTable <T> from, DataSet <TSource> source, CandidateKey targetKey, CancellationToken ct)
     where TSource : Model, new()
 {
     if (source.Count == 0)
     {
         return(0);
     }
     return(await from.DbSession.DeleteAsync(source, from, targetKey, ct));
 }
コード例 #6
0
ファイル: DbTableUpdate.cs プロジェクト: xydoublez/RDO.Net
 public static async Task <int> ExecuteAsync <TSource>(DbTable <T> target, DataSet <TSource> source, Action <ColumnMapper, TSource, T> columnMapper, CandidateKey targetKey,
                                                       CancellationToken ct)
     where TSource : class, IEntity, new()
 {
     if (source.Count == 0)
     {
         return(0);
     }
     return(await target.DbSession.UpdateAsync(source, target, columnMapper, targetKey, ct));
 }