Пример #1
0
        public static void Init()
        {
            SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString      = Config.ConnectionString,
                DbType                = DbType.Oracle,
                IsAutoCloseConnection = true,

                InitKeyType = InitKeyType.Attribute,
            });

            //调式代码 用来打印SQL
            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine(sql);
            };

            var id = Enumerable.Range(0, 100).ToList();

            //   id = null;
            Db.Queryable <Order>().Where(it => id.Contains(it.Id)).ToList();
            Db.Insertable(new Order()
            {
                Name = "A", Price = 1, CustomId = 1, CreateTime = DateTime.Now.AddDays(-2)
            }).ExecuteCommand();
            var list  = Db.Queryable <Order>().Where(it => Convert.ToDecimal(1.01) == Convert.ToDecimal(1.01)).ToList();;
            var list2 = Db.Queryable <Order>().Where(it => it.CreateTime > SqlFunc.DateAdd(SqlFunc.GetDate(), -3)).ToList();;

            var x = Db.Ado.SqlQuery <Order>("select null as price from dual").ToList();
        }
Пример #2
0
        private void DateAddDay()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateAdd(x2, 1) == x2;
            SqlServerExpressionContext         expContext = new SqlServerExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "((DATEADD(day,@MethodConst1,@MethodConst0)) = @Const2 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", 1), new SugarParameter("@Const2", x2)
            }, "DateIsSameByType error");
        }
Пример #3
0
        private void DateAddByType()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateAdd(x2, 11, DateType.Millisecond) == x2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "((DATE_ADD(@MethodConst0 , INTERVAL @MethodConst1 Millisecond)) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", 11), new SugarParameter("@Const3", x2)
            }, "DateAddByType error");
        }
Пример #4
0
        private void DateAddByType()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateAdd(x2, 11, DateType.Minute) == x2;
            SqliteExpressionContext            expContext = new SqliteExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(DATETIME(DATETIME(@MethodConst0), '+11 Minutes') = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", 11), new SugarParameter("@Const3", x2)
            }, "DateAddByType error");
        }
Пример #5
0
        private void DateAddDay()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateAdd(x2, 1) == x2;
            OracleExpressionContext            expContext = new OracleExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "((:MethodConst0+(1*:MethodConst1)) = :Const2 )", new List <SugarParameter>()
            {
                new SugarParameter(":MethodConst0", x2), new SugarParameter(":MethodConst1", 1), new SugarParameter(":Const2", x2)
            }, "DateAddDay error");
        }