예제 #1
0
        /// <summary>
        /// 批量插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table"></param>
        /// <param name="options"></param>
        /// <param name="source">插入对象的集合</param>
        /// <returns></returns>
        public static BulkCopyRowsCopied BulkCopy <T>([JetBrains.Annotations.NotNull] this ITable <T> table, BulkCopyOptions options, IEnumerable <T> source)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            var tbl            = (Table <T>)table;
            var dataConnection = tbl.DataContextInfo.DataContext as DataConnection;

            if (dataConnection == null)
            {
                throw new ArgumentException("DataContext must be of DataConnection type.");
            }

            if (options.TableName == null)
            {
                options.TableName = tbl.TableName;
            }
            if (options.DatabaseName == null)
            {
                options.DatabaseName = tbl.DatabaseName;
            }
            if (options.SchemaName == null)
            {
                options.SchemaName = tbl.SchemaName;
            }

            return(dataConnection.DataProvider.BulkCopy(dataConnection, options, source));
        }
예제 #2
0
        //public static DataReader ExecuteReader(
        //	this DataConnection    connection,
        //	string                 sql,
        //	CommandType            commandType,
        //	CommandBehavior        commandBehavior,
        //	params DataParameter[] parameters)
        //{
        //	return new CommandInfo(connection, sql, parameters)
        //	{
        //		CommandType     = commandType,
        //	}.ExecuteReader();
        //}

        #endregion

        #region BulkCopy

        /// <summary>
        /// 带设置条件的去批量插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dataConnection"></param>
        /// <param name="options">设置条件</param>
        /// <param name="source">插入对象的集合</param>
        /// <returns></returns>
        public static BulkCopyRowsCopied BulkCopy <T>([JetBrains.Annotations.NotNull] this DataConnection dataConnection, BulkCopyOptions options, IEnumerable <T> source)
        {
            if (dataConnection == null)
            {
                throw new ArgumentNullException("dataConnection");
            }
            return(dataConnection.DataProvider.BulkCopy(dataConnection, options, source));
        }