コード例 #1
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void DateValue()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateValue(x2, DateType.Year) == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, " ((@MethodConst1(@MethodConst0)) = @Const2 ) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", DateType.Year), new SugarParameter("@Const2", 1)
            }, "DateValue error");
        }
コード例 #2
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void DateAddDay()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateAdd(x2, 1) == 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(@MethodConst1 INTERVAL @MethodConst0 day)) = @Const2 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", 1), new SugarParameter("@Const2", x2)
            }, "DateIsSameByType error");
        }
コード例 #3
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void ExtendDate()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => Convert.ToDateTime("2015-1-1") == x2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "2015-1-1"), new SugarParameter("@Const1", x2)
            }, "ExtendDate error");
        }
コード例 #4
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void ToInt32()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToInt32("3") == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "3"), new SugarParameter("@Const1", 1)
            }, "ToInt32 error");
        }
コード例 #5
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void ToGuid()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToGuid("A94027A3-476E-478D-8228-F4054394B874") == x2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(CAST(@MethodConst0 AS CHAR) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "A94027A3-476E-478D-8228-F4054394B874"), new SugarParameter("@Const1", x2)
            }, "ToGuid error");
        }
コード例 #6
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void ToDouble()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToDouble("2") == 2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(CAST(@MethodConst0 AS DECIMAL(18,4)) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "2"), new SugarParameter("@Const1", (Double)2)
            }, "ToDouble error");
        }
コード例 #7
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void ToBool()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToBool("true") == true;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "true"), new SugarParameter("@Const1", (bool)true)
            }, "ToBool error");
        }
コード例 #8
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void ExtendSubstring()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => "aaaa".Substring(0, 2) == "a";
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(SUBSTRING(@MethodConst0,1 + @MethodConst1,@MethodConst2) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "aaaa"), new SugarParameter("@MethodConst1", 0), new SugarParameter("@MethodConst2", 2), new SugarParameter("@Const3", "a")
            }, "Substring error");
        }
コード例 #9
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void Replace()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Replace("aaaa", "a", "1") == "a";
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(REPLACE(@MethodConst0,@MethodConst1,@MethodConst2) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "aaaa"), new SugarParameter("@MethodConst1", "a"), new SugarParameter("@MethodConst2", "1"), new SugarParameter("@Const3", "a")
            }, "Replace error");
        }
コード例 #10
0
        private void StringIsNullOrEmpty4()
        {
            WhereConst.name = "xx";
            Expression <Func <Student, bool> > exp        = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(WhereConst.name);;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(( @Id0 = `Id` ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst1", "xx"),
                new SugarParameter("@Id0", 2)
            }, "StringIsNullOrEmpty4 error");
        }
コード例 #11
0
ファイル: Where.cs プロジェクト: zdl8061/sqlsugar
        private void whereSingle4()
        {
            Expression <Func <Student, bool> > exp = it => (it.Id > 1 && it.Name != "a") || it.Name == "a1";
            ExpressionContext expContext           = new MySqlExpressionContext();

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

            base.Check(value, pars, " ((( `Id` > @Id0 ) AND ( `Name` <> @Name1 )) OR ( `Name` = @Name2 ))  ", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 1),
                new SugarParameter("@Name1", "a"),
                new SugarParameter("@Name2", "a1")
            }, "whereSingle4");
        }
コード例 #12
0
ファイル: Method.cs プロジェクト: ewin66/Module.Demo
        private void DateIsSameByType()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateIsSame(x2, x2, DateType.Millisecond);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, " (TIMESTAMPDIFF(@MethodConst2,@MethodConst0,@MethodConst1)=0) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", x2),
                new SugarParameter("@MethodConst2", DateType.Millisecond)
            }, "DateIsSameByType error");
        }
コード例 #13
0
        private void IIF2()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.IIF(SqlFunc.Contains(it.Name, "a"), 1, 2) == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(( CASE  WHEN  (`Name` like concat('%',@MethodConst0,'%'))  THEN @MethodConst1  ELSE @MethodConst2 END ) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a"),
                new SugarParameter("@MethodConst1", 1),
                new SugarParameter("@MethodConst2", 2),
                new SugarParameter("@Const3", 1)
            }, "IIF2 error");
        }
コード例 #14
0
        private void IIF()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.IIF(it.Id == 1, 1, 2) == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

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

            base.Check(value, pars, "(( CASE  WHEN ( `Id` = @Id0 ) THEN @MethodConst1  ELSE @MethodConst2 END ) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 1),
                new SugarParameter("@MethodConst1", 1),
                new SugarParameter("@MethodConst2", 2),
                new SugarParameter("@Const3", 1)
            }, "IIF error");
        }
コード例 #15
0
ファイル: Where.cs プロジェクト: zdl8061/sqlsugar
        private void WhereMultiple2()
        {
            string name = "a";

            WhereConst.name = "a1";
            Expression <Func <Student, bool> > exp = it => (it.Id > 1 && it.Name != name || it.Id == 1) || it.Name == WhereConst.name;
            ExpressionContext expContext           = new MySqlExpressionContext();

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

            base.Check(value, pars, " (((( `it`.`Id` > @Id0 ) AND ( `it`.`Name` <> @Name1 )) OR ( `it`.`Id` = @Id2 )) OR ( `it`.`Name` = @Name3 ))", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 1),
                new SugarParameter("@Name1", "a"),
                new SugarParameter("@Id2", 1),
                new SugarParameter("@Name3", "a1")
            }, "WhereMultiple2");
        }