Beispiel #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="connection"></param>
        /// <param name="param"></param>
        /// <param name="predicate"></param>
        /// <param name="transaction"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public static int Delete <TEntity>(this IDbConnection connection, IEnumerable <TEntity> param,
                                           Expression <Func <TEntity, bool> > predicate = null,
                                           IDbTransaction transaction = null, int?commandTimeout = null)
            where TEntity : BaseEntity
        {
            ISqlAdapter adapter = GetSqlAdapter(connection);

            var sql = adapter.GetDelete(predicate);

            var result = 0;

            if (param == null && predicate != null)
            {
                if (!adapter.ParamValues.ContainsKey("ModifyTime"))
                {
                    adapter.ParamValues.TryAdd("ModifyTime", DateTime.Now);
                }
                if (!adapter.ParamValues.ContainsKey("ModifyBy"))
                {
                    adapter.ParamValues.TryAdd("ModifyBy", HttpContextHelper.GetOperator());
                }

                result = connection.ExecuteExt(sql, adapter.ParamValues, transaction, commandTimeout, isExecuteSql: true);
            }
            else
            {
                result = connection.ExecuteExt(sql, param, transaction, commandTimeout);
            }

            return(result);
        }