Ejemplo n.º 1
0
        public static int BulkInsertOracleDb <T>(this IDbConnection con, IEnumerable <T> dataList, int linesPerBatch = 1000, int timeout = 0, DMLOptions options = null)
        {
            if (!(con is OracleConnection))
            {
                throw new Exception("invalid connection");
            }
            int res = 0;

            if (dataList.HasAny())
            {
                var oracleCon = con as OracleConnection;
                if (oracleCon.State != ConnectionState.Open)
                {
                    oracleCon.Open();
                }
                using (var command = oracleCon.CreateCommand())
                {
                    command.CommandText = Statements <T> .GetInsert(options);

                    command.CommandType    = CommandType.Text;
                    command.BindByName     = true;
                    command.CommandTimeout = timeout;
                    var columns = typeof(T).GetMembers <PropertyInfo>();

                    int items    = dataList.Count();
                    int outcount = 0;
                    while (outcount < items)
                    {
                        int incount = linesPerBatch > items - outcount ? items - outcount : linesPerBatch;
                        command.ArrayBindCount = incount;
                        command.Parameters.Clear();
                        foreach (var c in columns)
                        {
                            command.Parameters.Add(c.Name.SetParameterDelimeter(options), c.PropertyType.ToOracleType(), dataList.Skip(outcount).Take(incount).Select(i => c.GetValue(i)).ToArray(), ParameterDirection.Input);
                        }
                        outcount += incount;
                        res      += command.ExecuteNonQuery();
                    }
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Not to be used for many objects due to performance issues
 /// </summary>
 public static int MultipleInsert <T>(this IDbConnection con, IEnumerable <T> dataList, IDbTransaction trn = null, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     return(con.Execute(Statements <T> .GetInsert(options), ToParamObjectList(dataList, options), trn, timeout, commandType));
 }
Ejemplo n.º 3
0
 public static int Insert <T>(this IDbConnection con, T data, IDbTransaction trn = null, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     return(con.Execute(Statements <T> .GetInsert(options), data, trn, timeout, commandType));
 }
Ejemplo n.º 4
0
        public static int BulkInsertOracleDb <T>(this IDbConnection con, IEnumerable <T> dataList, Func <PropertyInfo, Boolean> filter, int linesPerBatch = 1000, int timeout = 0, DMLOptions options = null)
        {
            DMLOptions curOptions  = options ?? OracleDefaultOptions;
            string     commandText = filter != null ? Statements <T> .GetFilteredInsert(filter, curOptions) : Statements <T> .GetInsert(curOptions);

            return(con.BulkInsert(dataList, commandText, linesPerBatch, timeout, curOptions));
        }
Ejemplo n.º 5
0
        public static int BulkInsertOracleDb <T>(this IDbConnection con, IEnumerable <T> dataList, int linesPerBatch = 1000, int timeout = 0, DMLOptions options = null)
        {
            DMLOptions curOptions = options ?? OracleDefaultOptions;

            return(con.BulkInsert(dataList, Statements <T> .GetInsert(curOptions), linesPerBatch, timeout, curOptions));
        }