Beispiel #1
0
        /// <summary>
        /// 批量假删除
        /// 注意:whereIn field 为class中的第一个属性
        /// 使用说明::
        /// FalseDelete《T》("is_del",new int[]{1,2,3})或者Delete《T》("is_del",3)
        /// </summary>
        /// <param name="field">更新删除状态字段</param>
        /// <param name="whereIn">delete ids</param>
        public bool FalseDelete <T>(string field, params dynamic[] whereIn)
        {
            Type type = typeof(T);
            //属性缓存
            string cachePropertiesKey     = "db." + type.Name + ".GetProperties";
            var    cachePropertiesManager = CacheManager <PropertyInfo[]> .GetInstance();

            PropertyInfo[] props     = SqlSugarTool.GetGetPropertiesByCache(type, cachePropertiesKey, cachePropertiesManager);
            bool           isSuccess = false;

            if (whereIn != null && whereIn.Length > 0)
            {
                string sql            = string.Format("UPDATE  {0} SET {3}=0 WHERE {1} IN ({2})", type.Name, props[0].Name, whereIn.ToJoinSqlInVal(), field);
                int    deleteRowCount = ExecuteCommand(sql);
                isSuccess = deleteRowCount > 0;
            }
            return(isSuccess);
        }
Beispiel #2
0
 /// <summary>
 /// 批量假删除
 /// 使用说明::
 /// FalseDelete《T》("is_del",new int[]{1,2,3})或者Delete《T》("is_del",3)
 /// </summary>
 /// <param name="field">更新删除状态字段</param>
 /// <param name="whereIn">delete ids</param>
 public bool FalseDelete<T, FiledType>(string field, params FiledType[] whereIn)
 {
     Type type = typeof(T);
     string typeName = type.Name;
     typeName = GetTableNameByClassType(typeName);
     //属性缓存
     string cachePropertiesKey = "db." + typeName + ".GetProperties";
     var cachePropertiesManager = CacheManager<PropertyInfo[]>.GetInstance();
     PropertyInfo[] props = SqlSugarTool.GetGetPropertiesByCache(type, cachePropertiesKey, cachePropertiesManager);
     bool isSuccess = false;
     if (whereIn != null && whereIn.Length > 0)
     {
         string sql = string.Format("UPDATE  {0} SET {3}=1 WHERE {1} IN ({2})", typeName, SqlSugarTool.GetPrimaryKeyByTableName(this, typeName), whereIn.ToJoinSqlInVal(), field);
         int deleteRowCount = ExecuteCommand(sql);
         isSuccess = deleteRowCount > 0;
     }
     return isSuccess;
 }
Beispiel #3
0
        /// <summary>
        /// 批量删除
        /// 注意:whereIn field 为class中的第一个属性
        /// 使用说明:Delete《T》(new int[]{1,2,3}) 或者  Delete《T》(3)
        /// </summary>
        /// <param name="whereIn"> delete ids </param>
        public bool Delete <T>(params Guid[] whereIn)
        {
            Type type = typeof(T);
            //属性缓存
            string cachePropertiesKey     = "db." + type.Name + ".GetProperties";
            var    cachePropertiesManager = CacheManager <PropertyInfo[]> .GetInstance();

            PropertyInfo[] props     = SqlSugarTool.GetGetPropertiesByCache(type, cachePropertiesKey, cachePropertiesManager);
            string         key       = type.FullName;
            bool           isSuccess = false;

            if (whereIn != null && whereIn.Length > 0)
            {
                string sql            = string.Format("DELETE FROM {0} WHERE {1} IN ({2})", type.Name, props[0].Name, whereIn.ToJoinSqlInVal());
                int    deleteRowCount = ExecuteCommand(sql);
                isSuccess = deleteRowCount > 0;
            }
            return(isSuccess);
        }
        /// <summary>
        /// 根据指定列集合批量删除数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <typeparam name="FiledType">指定列的类型</typeparam>
        /// <param name="expression">表达式条件</param>
        /// <param name="whereIn">批定列值的集合</param>
        /// <returns>删除成功返回true</returns>
        public bool Delete <T, FiledType>(Expression <Func <T, object> > expression, params FiledType[] whereIn)
        {
            ResolveExpress re        = new ResolveExpress();
            var            fieldName = re.GetExpressionRightField(expression);
            Type           type      = typeof(T);
            string         typeName  = type.Name;

            typeName = GetTableNameByClassType(typeName);
            //属性缓存
            string cachePropertiesKey     = "db." + type.FullName + ".GetProperties";
            var    cachePropertiesManager = CacheManager <PropertyInfo[]> .GetInstance();

            PropertyInfo[] props     = SqlSugarTool.GetGetPropertiesByCache(type, cachePropertiesKey, cachePropertiesManager);
            bool           isSuccess = false;

            if (whereIn != null && whereIn.Length > 0)
            {
                string sql            = string.Format("DELETE FROM [{0}] WHERE {1} IN ({2})", typeName, fieldName, whereIn.ToJoinSqlInVal());
                int    deleteRowCount = ExecuteCommand(sql);
                isSuccess = deleteRowCount > 0;
            }
            return(isSuccess);
        }