Пример #1
0
 public static int Insert <T>(this IDbConnection con, T data, Func <PropertyInfo, Boolean> columnFilter, IDbTransaction trn = null, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     if (columnFilter == null)
     {
         return(Insert(con, data, trn, timeout, commandType, options));
     }
     return(con.Execute(Statements <T> .GetFilteredInsert(columnFilter, options), ToParamObject(data, options), trn, timeout, commandType));
 }
Пример #2
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);
        }
Пример #3
0
        public static int Count <T>(this IDbConnection con, object whereObject, IDbTransaction trn = null, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
        {
            var res = con.QueryFirst <Count>(Statements <T> .GetCount(whereObject, options), ToParamObject(whereObject, options), trn, timeout, commandType);

            return(res?.Found ?? 0);
        }
Пример #4
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));
 }
Пример #5
0
 public static int Update <T>(this IDbConnection con, object updateObject, object whereObject, IDbTransaction trn = null, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     return(con.Execute(Statements <T> .GetUpdate(updateObject, whereObject, options), GetMergedDynamicParams(updateObject, whereObject), trn, timeout, commandType));
 }
Пример #6
0
 public static int Delete <T>(this IDbConnection con, object whereObject, IDbTransaction trn = null, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     return(con.Execute(Statements <T> .GetDelete(whereObject, options), ToParamObject(whereObject, options), trn, timeout, commandType));
 }
Пример #7
0
 public static IEnumerable <T> Select <T>(this IDbConnection con, object whereObject, IDbTransaction trn = null, bool buffered = true, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     return(con.Query <T>(Statements <T> .GetSelect(whereObject, options), ToParamObject(whereObject, options), trn, buffered, timeout, commandType));
 }
Пример #8
0
 public static IEnumerable <T> Select <T>(this IDbConnection con, DMLOptions options = null)
 {
     return(con.Query <T>(Statements <T> .GetSelect(options)));
 }
Пример #9
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));
 }
Пример #10
0
 public static T SelectSingle <T>(this IDbConnection con, object whereObject, IDbTransaction trn = null, bool buffered = true, int?timeout = 0, CommandType?commandType = null, DMLOptions options = null)
 {
     return(con.Query <T>(Statements <T> .GetSelect(whereObject, options), whereObject, trn, buffered, timeout, commandType).FirstOrDefault());
 }
Пример #11
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));
        }
Пример #12
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));
        }
Пример #13
0
 public static IEnumerable <T> Select <T>(this IDbConnection con)
 {
     return(con.Query <T>(Statements <T> .GetSelect()));
 }