Example #1
0
        private void Equals_2()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Equals(it.Name, it.Name);
            SqlServerExpressionContext         expContext = new SqlServerExpressionContext();

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

            base.Check(value, pars, " ([Name] = [Name]) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a")
            }, "Equals1 error");


            Expression <Func <Student, bool> > exp2        = it => SqlFunc.Equals("a", "a2");
            SqlServerExpressionContext         expContext2 = new SqlServerExpressionContext();

            expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
            var value2 = expContext2.Result.GetString();
            var pars2  = expContext2.Parameters;

            base.Check(value2, pars2, " (@MethodConst0 = @MethodConst1) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a"), new SugarParameter("@MethodConst1", "a2")
            }, "Equals2 error");
        }
        public void AddAccountInfoHistory(string name, string bankOfDeposit, string account)
        {
            name          = string.IsNullOrWhiteSpace(name) ? string.Empty : name;
            bankOfDeposit = string.IsNullOrWhiteSpace(bankOfDeposit) ? string.Empty : bankOfDeposit;
            account       = string.IsNullOrWhiteSpace(account) ? string.Empty : account;

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(bankOfDeposit) || string.IsNullOrWhiteSpace(account))
            {
                return;
            }

            var query = BusDb.Queryable <DH_AccountInfoHistory>()
                        .Where(m => SqlFunc.Equals(m.Name, name) && SqlFunc.Equals(m.BankOfDeposit, bankOfDeposit) && SqlFunc.Equals(m.Account, account)).ToList();

            if (query.Count > 0)
            {
                return;
            }

            DH_AccountInfoHistory info = new DH_AccountInfoHistory()
            {
                Id            = Guid.NewGuid(),
                Name          = name,
                BankOfDeposit = bankOfDeposit,
                Account       = account
            };

            BusDb.Insertable(info).ExecuteCommand();
        }
Example #3
0
        private void Equals()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Equals(it.Name, "a");
            OracleExpressionContext            expContext = new OracleExpressionContext();

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

            base.Check(value, pars, " (\"NAME\" = :MethodConst0) ", new List <SugarParameter>()
            {
                new SugarParameter(":MethodConst0", "a")
            }, "Equals1 error");


            Expression <Func <Student, bool> > exp2        = it => SqlFunc.Equals("a", it.Name);
            OracleExpressionContext            expContext2 = new OracleExpressionContext();

            expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
            var value2 = expContext2.Result.GetString();
            var pars2  = expContext2.Parameters;

            base.Check(value2, pars2, " (:MethodConst0 = \"NAME\") ", new List <SugarParameter>()
            {
                new SugarParameter(":MethodConst0", "a")
            }, "Equals2 error");
        }
Example #4
0
        public static void Queryable()
        {
            var pageindex = 1;
            var pagesize  = 10;
            var total     = 0;
            var totalPage = 0;
            var list      = Db.Queryable <Order>().ToPageList(pageindex, pagesize, ref total, ref totalPage);

            //Db.CodeFirst.InitTables(typeof(CarType));
            //Db.Updateable<CarType>()
            //      .SetColumns(it => new CarType { State = SqlSugar.SqlFunc.IIF(it.State == true, false, true) }).Where(it => true)
            //   .ExecuteCommand();

            //Db.CodeFirst.InitTables(typeof(TestTree));
            //Db.DbMaintenance.TruncateTable<TestTree>();
            //Db.Ado.ExecuteCommand("insert testtree values(hierarchyid::GetRoot(),geography :: STGeomFromText ('POINT(55.9271035250276 -3.29431266523898)',4326),'name')");
            //var list2 = Db.Queryable<TestTree>().ToList();

            Db.CodeFirst.InitTables <UnitGuidTable>();
            Db.Queryable <UnitGuidTable>().Where(it => it.Id.HasValue).ToList();

            Db.Queryable <Order>().Where(it => SqlFunc.Equals(it.CreateTime.Date, it.CreateTime.Date)).ToList();

            var sql = Db.Queryable <UnitSelectTest>().Select(it => new UnitSelectTest()
            {
                DcNull = it.Dc,
                Dc     = it.Int
            }).ToSql().Key;

            UValidate.Check(sql, "SELECT  [Dc] AS [DcNull] , [Int] AS [Dc]  FROM [UnitSelectTest]", "Queryable");

            sql = Db.Updateable <UnitSelectTest2>(new UnitSelectTest2()).ToSql().Key;
            UValidate.Check(sql, @"UPDATE [UnitSelectTest2]  SET
           [Dc]=@Dc,[IntNull]=@IntNull  WHERE [Int]=@Int", "Queryable");

            sql = Db.Queryable <Order>().IgnoreColumns(it => it.CreateTime).ToSql().Key;
            UValidate.Check(sql, "SELECT [Id],[Name],[Price],[CustomId] FROM [Order] ", "Queryable");
            sql = Db.Queryable <Order>().IgnoreColumns(it => new { it.Id, it.Name }).ToSql().Key;
            UValidate.Check(sql, "SELECT [Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
            sql = Db.Queryable <Order>().IgnoreColumns("id").ToSql().Key;
            UValidate.Check(sql, "SELECT [Name],[Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");

            var cts   = IEnumerbleContains.Data();
            var list2 = Db.Queryable <Order>()
                        .Where(p => /*ids.*/ cts.Select(c => c.Id).Contains(p.Id)).ToList();

            var cts2  = IEnumerbleContains.Data().ToList();;
            var list3 = Db.Queryable <Order>()
                        .Where(p => /*ids.*/ cts2.Select(c => c.Id).Contains(p.Id)).ToList();


            var list4 = Db.Queryable <Order>()
                        .Where(p => new List <int> {
                1, 2, 3
            }.Where(b => b > 1).Contains(p.Id)).ToList();

            Db.CodeFirst.InitTables <UnitTest3>();
            var list5 = Db.Queryable <UnitTest3>().Where(it => SqlFunc.ToString(it.Date.Value.Year) == "1").ToList();
            var list6 = Db.Queryable <UnitTest3>().Where(it => it.Date.Value.Year == 1).ToList();
            var list7 = Db.Queryable <UnitTest3>().Where(it => it.Date.Value.Date == DateTime.Now.Date).ToList();


            SaleOrder saleOrderInfo = new SaleOrder();

            Db.CodeFirst.InitTables <SaleOrder>();
            var result = Db.GetSimpleClient <SaleOrder>().Update(o => new SaleOrder()
            {
                OrderStatus = 1,
                CheckMan    = saleOrderInfo.CheckMan,
                CheckTime   = DateTime.Now
            }, o => o.OrderSn == saleOrderInfo.OrderSn && o.OrderStatus != 1);
        }
Example #5
0
        public void Init()
        {
            var communityId = "";
            var buildId     = "";
            var unitId      = "";
            var keyword     = "";

            GetInstance().CodeFirst.InitTables(typeof(MainTable), typeof(SubTable));
            GetInstance().Queryable <MainTable>().Where(u =>
                                                        (u.CommunityID == communityId || SqlFunc.IsNullOrEmpty(communityId)) &&
                                                        (SqlFunc.Contains(u.BuildID, buildId) || SqlFunc.IsNullOrEmpty(buildId)) &&
                                                        (SqlFunc.Contains(u.UnitID, unitId) || SqlFunc.IsNullOrEmpty(unitId)) &&
                                                        (SqlFunc.Contains(u.RoomNumber, keyword) || SqlFunc.Contains(u.RoomerName, keyword) ||
                                                         SqlFunc.Contains(u.HousePlace, keyword) || SqlFunc.Contains(u.UnitName, keyword) ||
                                                         SqlFunc.Contains(u.BuildName, keyword) || SqlFunc.IsNullOrEmpty(keyword)))
            .GroupBy(ru => new { ru.RoomNumber, ru.RoomID })
            .Select(ru => new
            {
                RoomNumber  = SqlFunc.AggregateMax(ru.RoomNumber),
                CountRoomer = SqlFunc.AggregateCount(ru.RoomerName),
                RoomID      = SqlFunc.AggregateMax(ru.RoomID),
                Owner       = SqlFunc.Subqueryable <SubTable>().Where(r => r.RoomID == ru.RoomID && SqlFunc.Equals(r.RoomUserType, "业主") && SqlFunc.Equals(r.RoomUserType, "业主")).Select(s => s.RoomerName)
            }).OrderBy((r) => r.RoomNumber, type: OrderByType.Desc).ToPageListAsync(1, 2).Wait();

            GetInstance().Updateable <Student>().UpdateColumns(it =>
                                                               new Student()
            {
                Name       = "a".ToString(),
                CreateTime = DateTime.Now.AddDays(-1)
            }
                                                               ).Where(it => it.Id == 1).ExecuteCommand();


            var list = GetInstance().Queryable <Student, School>((st, sc) => new object[] {
                JoinType.Left, st.SchoolId == sc.Id && st.CreateTime == DateTime.Now.AddDays(-1)
            })
                       .Where(st => st.Name == "jack").ToList();


            GetInstance().Updateable <BugStudent>().Where(it => true).UpdateColumns(it => new BugStudent()
            {
                Float = 11
            }).ExecuteCommand();
            var reslut = GetInstance().Queryable <BugStudent>().ToList();
        }