Example #1
0
 /// <summary>
 /// 打印输出
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="builder"></param>
 /// <param name="description"></param>
 /// <param name="separator"></param>
 public static void Print <T>(SqlBuilderCore <T> builder, string description = "", string separator = "") where T : class, new()
 {
     if (!string.IsNullOrEmpty(separator))
     {
         Console.ForegroundColor = ConsoleColor.Magenta;
         Console.WriteLine($"--------------------------------[ {separator} ]----------------------------------");
         Console.WriteLine();
     }
     if (!string.IsNullOrEmpty(description))
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(description);
     }
     if (builder != null)
     {
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine(builder.Sql);
         if (builder.Parameters != null)
         {
             foreach (KeyValuePair <string, (object data, DataTypeAttribute type)> item in builder.Parameters)
             {
                 Console.WriteLine(item.ToString());
             }
         }
     }
     Console.WriteLine();
 }
Example #2
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="databaseType">数据库类型</param>
        /// <param name="sqlIntercept">sql拦截委托</param>
        /// <param name="isEnableFormat">是否启用对表名和列名格式化,默认启用</param>
        /// <returns>SqlBuilderCore</returns>
        public static SqlBuilderCore <T> Delete <T>(
            DatabaseType databaseType = DatabaseType.SQLServer,
            Func <string, object, string> sqlIntercept = null,
            bool isEnableFormat = true)
            where T : class
        {
            var builder = new SqlBuilderCore <T>(databaseType, sqlIntercept, isEnableFormat).Delete();

            return(builder);
        }
Example #3
0
        /// <summary>
        /// Sum
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="expression">表达式树</param>
        /// <param name="databaseType">数据库类型</param>
        /// <param name="sqlIntercept">sql拦截委托</param>
        /// <param name="isEnableFormat">是否启用对表名和列名格式化,默认启用</param>
        /// <returns>SqlBuilderCore</returns>
        public static SqlBuilderCore <T> Sum <T>(
            Expression <Func <T, object> > expression,
            DatabaseType databaseType = DatabaseType.SQLServer,
            Func <string, object, string> sqlIntercept = null,
            bool isEnableFormat = true)
            where T : class
        {
            var builder = new SqlBuilderCore <T>(databaseType, sqlIntercept, isEnableFormat).Sum(expression);

            return(builder);
        }
Example #4
0
        /// <summary>
        /// Insert
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="expression">表达式树</param>
        /// <param name="databaseType">数据库类型</param>
        /// <param name="isEnableNullValue">是否对null值属性进行sql拼接操作,默认:是</param>
        /// <param name="sqlIntercept">sql拦截委托</param>
        /// <param name="isEnableFormat">是否启用对表名和列名格式化,默认启用</param>
        /// <returns>SqlBuilderCore</returns>
        public static SqlBuilderCore <T> Insert <T>(
            Expression <Func <object> > expression = null,
            DatabaseType databaseType = DatabaseType.SQLServer,
            bool isEnableNullValue    = true,
            Func <string, object, string> sqlIntercept = null,
            bool isEnableFormat = true)
            where T : class
        {
            var builder = new SqlBuilderCore <T>(databaseType, sqlIntercept, isEnableFormat).Insert(expression, isEnableNullValue);

            return(builder);
        }
Example #5
0
        /// <summary>
        /// Select
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <typeparam name="T2">泛型类型2</typeparam>
        /// <typeparam name="T3">泛型类型3</typeparam>
        /// <typeparam name="T4">泛型类型4</typeparam>
        /// <typeparam name="T5">泛型类型5</typeparam>
        /// <param name="expression">表达式树</param>
        /// <param name="databaseType">数据库类型</param>
        /// <param name="sqlIntercept">sql拦截委托</param>
        /// <param name="isEnableFormat">是否启用对表名和列名格式化,默认启用</param>
        /// <returns>SqlBuilderCore</returns>
        public static SqlBuilderCore <T> Select <T, T2, T3, T4, T5>(
            Expression <Func <T, T2, T3, T4, T5, object> > expression = null,
            DatabaseType databaseType = DatabaseType.SQLServer,
            Func <string, object, string> sqlIntercept = null,
            bool isEnableFormat = true)
            where T : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
        {
            var builder = new SqlBuilderCore <T>(databaseType, sqlIntercept, isEnableFormat).Select(expression);

            return(builder);
        }