Example #1
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;
		}
Example #2
0
 protected UpserterBase(SqlTableSchema targetTableSchema)
 {
     if (targetTableSchema == null)
     {
         throw new ArgumentNullException("targetTableSchema");
     }
     TargetTableSchema = targetTableSchema;
 }
Example #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));
            }
        }
Example #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;
 }
Example #5
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;
 }
Example #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");
		}
Example #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;
 }
        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");
            }
        }
Example #9
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);
		}
Example #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));
        }
Example #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;
 }
Example #12
0
		protected UpserterBase(SqlTableSchema targetTableSchema)
		{
			if (targetTableSchema == null) throw new ArgumentNullException("targetTableSchema");
			TargetTableSchema = targetTableSchema;
		}
 public DataTableUpserter(SqlTableSchema targetTableSchema) : base(targetTableSchema)
 {
 }
Example #14
0
		public DataTableUpserter(SqlTableSchema targetTableSchema) : base(targetTableSchema) { }