コード例 #1
0
ファイル: MergeCommand.cs プロジェクト: GrgDmr/CDAManager
		public MergeCommand(SqlTableSchema sourceTableSchema, SqlTableSchema targetTableSchema)
		{
			if (sourceTableSchema == null) throw new ArgumentNullException("sourceTableSchema");
			if (targetTableSchema == null) throw new ArgumentNullException("targetTableSchema");
			_sourceTableSchema = sourceTableSchema;
			_targetTableSchema = targetTableSchema;
		}
コード例 #2
0
 protected UpserterBase(SqlTableSchema targetTableSchema)
 {
     if (targetTableSchema == null)
     {
         throw new ArgumentNullException("targetTableSchema");
     }
     TargetTableSchema = targetTableSchema;
 }
コード例 #3
0
        protected Dictionary <int, int> PerformUpsert(SqlConnection connection, ICollection <string> columnNames, IDataReader dataReader)
        {
            SqlTableSchema tempTableSchema = GetTempTableSchema(TargetTableSchema, columnNames);

            using (var upsert = new Upsert(connection, TargetTableSchema, tempTableSchema, columnNames))
            {
                return(upsert.Execute(dataReader));
            }
        }
コード例 #4
0
 public TypedUpserter(SqlTableSchema targetTableSchema, Dictionary <string, Func <T, object> > columnMappings, Action <T, int> identUpdater)
     : base(targetTableSchema)
 {
     if (columnMappings == null)
     {
         throw new ArgumentNullException("columnMappings");
     }
     _columnMappings = columnMappings;
     _identUpdater   = identUpdater;
 }
コード例 #5
0
ファイル: Upsert.cs プロジェクト: vermiceli/SqlBulkUpsert
 public Upsert(SqlConnection connection, SqlTableSchema targetTableSchema, SqlTableSchema tempTableSchema, ICollection<string> columnNames)
 {
     if (connection == null) throw new ArgumentNullException("connection");
     if (targetTableSchema == null) throw new ArgumentNullException("targetTableSchema");
     if (tempTableSchema == null) throw new ArgumentNullException("tempTableSchema");
     if (columnNames == null) throw new ArgumentNullException("columnNames");
     _connection = connection;
     _targetTableSchema = targetTableSchema;
     _tempTableSchema = tempTableSchema;
     _columnNames = columnNames;
 }
コード例 #6
0
		private void VerifyDataTable(DataTable dataTable, SqlTableSchema targetTableSchema)
		{
			// Ensure all columns in DataTable are in actual table schema
			foreach (DataColumn dataColumn in dataTable.Columns)
			{
				if (!targetTableSchema.Columns.Any(c => c.Name == dataColumn.ColumnName)) throw new Exception(String.Format("Column does not appear in table {0}", dataColumn.ColumnName));
			}

			// ensure primary key columns present in data table
			if (!targetTableSchema.PrimaryKeyColumns.All(c => dataTable.Columns.Contains(c.Name))) throw new Exception("Table primary key columns must feature in DataTable");
		}
コード例 #7
0
 public MergeCommand(SqlTableSchema sourceTableSchema, SqlTableSchema targetTableSchema)
 {
     if (sourceTableSchema == null)
     {
         throw new ArgumentNullException("sourceTableSchema");
     }
     if (targetTableSchema == null)
     {
         throw new ArgumentNullException("targetTableSchema");
     }
     _sourceTableSchema = sourceTableSchema;
     _targetTableSchema = targetTableSchema;
 }
コード例 #8
0
        private void VerifyDataTable(DataTable dataTable, SqlTableSchema targetTableSchema)
        {
            // Ensure all columns in DataTable are in actual table schema
            foreach (DataColumn dataColumn in dataTable.Columns)
            {
                if (!targetTableSchema.Columns.Any(c => c.Name == dataColumn.ColumnName))
                {
                    throw new Exception(String.Format("Column does not appear in table {0}", dataColumn.ColumnName));
                }
            }

            // ensure primary key columns present in data table
            if (!targetTableSchema.PrimaryKeyColumns.All(c => dataTable.Columns.Contains(c.Name)))
            {
                throw new Exception("Table primary key columns must feature in DataTable");
            }
        }
コード例 #9
0
ファイル: UpserterBase.cs プロジェクト: GrgDmr/CDAManager
		private SqlTableSchema GetTempTableSchema(SqlTableSchema targetTableSchema, ICollection<string> columnNames)
		{
			// only columns we're inserting
			var tempTableColumnList = targetTableSchema.Columns
				.Where(c => columnNames.Contains(c.Name))
				.Select(c =>
				{
					var tempCol = c.Clone();
					tempCol.Nullable = true;
					return tempCol;
				})
				.ToList();

			// Add surrogate identity for temp table
			tempTableColumnList.Insert(0, new IdentityColumn());

			// prepare temp table schema
			return new SqlTableSchema("#upsert", tempTableColumnList);
		}
コード例 #10
0
        private SqlTableSchema GetTempTableSchema(SqlTableSchema targetTableSchema, ICollection <string> columnNames)
        {
            // only columns we're inserting
            var tempTableColumnList = targetTableSchema.Columns
                                      .Where(c => columnNames.Contains(c.Name))
                                      .Select(c =>
            {
                var tempCol      = c.Clone();
                tempCol.Nullable = true;
                return(tempCol);
            })
                                      .ToList();

            // Add surrogate identity for temp table
            tempTableColumnList.Insert(0, new IdentityColumn());

            // prepare temp table schema
            return(new SqlTableSchema("#upsert", tempTableColumnList));
        }
コード例 #11
0
 public Upsert(SqlConnection connection, SqlTableSchema targetTableSchema, SqlTableSchema tempTableSchema, ICollection <string> columnNames)
 {
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (targetTableSchema == null)
     {
         throw new ArgumentNullException("targetTableSchema");
     }
     if (tempTableSchema == null)
     {
         throw new ArgumentNullException("tempTableSchema");
     }
     if (columnNames == null)
     {
         throw new ArgumentNullException("columnNames");
     }
     _connection        = connection;
     _targetTableSchema = targetTableSchema;
     _tempTableSchema   = tempTableSchema;
     _columnNames       = columnNames;
 }
コード例 #12
0
ファイル: UpserterBase.cs プロジェクト: GrgDmr/CDAManager
		protected UpserterBase(SqlTableSchema targetTableSchema)
		{
			if (targetTableSchema == null) throw new ArgumentNullException("targetTableSchema");
			TargetTableSchema = targetTableSchema;
		}
コード例 #13
0
 public DataTableUpserter(SqlTableSchema targetTableSchema) : base(targetTableSchema)
 {
 }
コード例 #14
0
		public DataTableUpserter(SqlTableSchema targetTableSchema) : base(targetTableSchema) { }