示例#1
0
        static void Main(string[] args)
        {
            BatchTest2.Test();

            Console.ReadLine();

            BatchTest.Test();


            MutiTablesTest.Test();



            //new DBTicketOrderRepository().Search().Where(b => b.C_id == "123sdf4asdfsadfgrewfdg5498432165").OrderBy(b=>b.C_price).ToFirst();


            //Test4();

            //Test3();

            var c_id = Guid.NewGuid().ToString("N");

            var dbtickerOrder = new DBTicketOrder()
            {
                C_id           = c_id,
                C_supplier     = 1,
                C_appId        = "s",
                C_channelId    = "22",
                C_sku          = "sss",
                C_outTradeNo   = "afefa",
                C_count        = 1,
                C_phone        = "1111",
                C_nonce        = "asfew",
                C_timestamp    = "asdfeaf",
                C_sign         = "afefqwaf",
                C_amount       = 19.80M,
                C_discountrate = 90F,
                C_activityName = "asdfasd",
                C_productName  = "asdfed",
                C_resv1        = "hello",
                C_created      = DateTime.Now
            };



            var c_price = (decimal)(((float)dbtickerOrder.C_amount) * dbtickerOrder.C_discountrate / 100F);

            dbtickerOrder.C_price = c_price;

            if (new DBTicketOrderRepository().Insert(dbtickerOrder) > 0)
            {
                Console.WriteLine($"DBTicketOrder数据插入成功,{dbtickerOrder.C_price}");

                var newdbtickerOrder = new DBTicketOrderRepository().GetDBTicketOrder(dbtickerOrder.C_id);

                Console.WriteLine($"DBTicketOrder数据查询成功,{newdbtickerOrder.C_price}");

                newdbtickerOrder.C_updated = DateTime.Now;

                newdbtickerOrder.C_resv1 = null;

                if (new DBTicketOrderRepository().Update(newdbtickerOrder) > 0)
                {
                    var newdbtickerOrder2 = new DBTicketOrderRepository().GetDBTicketOrder(c_id);

                    Console.WriteLine($"DBTicketOrder数据查询成功,{newdbtickerOrder2.C_price}");
                }
            }

            new DBTicketOrderRepository().Delete(c_id);

            Console.ReadLine();


            var db = new DBContext();

            var dt = db.FromSql("select * from tb_task").ToDataTable();

            var dttasks = dt.DataTableToEntityList <DBTask>();

            var taskModel = new TaskModel()
            {
                Crc32        = 123,
                TaskID       = Guid.NewGuid().ToString("N"),
                BeginTime    = DateTime.Now,
                BusinID      = "asdfead24545",
                CompanyId    = "54",
                CreateTime   = DateTime.Now,
                DayLimit     = 10,
                DayTimes     = 100,
                Description  = "𠂆𠂆𠂆𠂆𠂆𠂆𠂆𠂆",
                EndTime      = DateTime.Now,
                FlowType     = "5687653",
                IsDel        = false,
                IsEnabled    = true,
                Name         = "afeadfad545646546",
                Operator     = "5435635321",
                PlatformID   = "8423416534635",
                Point        = 2,
                TaskMaxPoint = 100,
                TaskType     = 3
            };



            var tn = taskModel.ConvertTo <DBTask>();

            var insertResult = new DBTaskRepository().Insert(tn);

            var taa = taskModel.ConvertTo <TestA>();

            var aa = new TestA()
            {
                aa  = DateTime.Now,
                Age = 10,
                //Created = "2019-04-22 22:53",
                id   = "100001",
                Num  = 10.235M,
                Num1 = 100
            };

            var bb = aa.ConvertTo <TestB>();

            var cc = bb.ConvertTo <TestA>();

            Console.WriteLine("WEF使用实例");

            Console.WriteLine("-----------------------------");



            var tasks = new DBTaskRepository().Search().ToList();

            DBUserTaskRepository userTaskRepository = null;

            var ts1 = Task.Factory.StartNew(() =>
            {
                userTaskRepository = new DBUserTaskRepository();
            });

            Task.WaitAll(ts1);

            var useTasks1 = userTaskRepository.Search().Where(b => b.Isenabled).ToList();

            var useTasks2 = userTaskRepository.Search().Where(b => b.Userid == "6312124585351742" && b.Isenabled).ToList();


            for (int i = 0; i < 10000; i++)
            {
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        userTaskRepository.Search().First();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });
            }


            Console.ReadLine();

            new DBTaskRepository().Delete("");

            var giftopt = new DBGiftRepository();

            var giftwhere = giftopt.Search().Where(b => b.Giftid.Contains("1"));

            giftwhere = giftwhere.Where(b => !b.Isdel && b.Isenabled); //不能连接


            giftwhere = giftwhere.OrderBy(b => b.Createtime).OrderByDescending(b => b.Giftid);//不能连接

            var glist = giftwhere.ToList();

            var glist2 = giftopt.Search().Where(b => b.Giftid.Like("1")).ToList();

            var giftids = giftopt.Search().Page(1, 10).ToList().Select(b => b.Giftid).ToList();

            var sum = giftopt.Search().Select(b => b.Supporttype.Sum()).ToFirstDefault().Supporttype;

            var avg = giftopt.Search().Select(b => b.Supporttype.Avg()).ToFirstDefault().Supporttype;

            var glist22 = giftopt.Search().Where(b => b.Giftid.In(giftids)).ToList();

            var gids = new List <string>();

            gids.Add("120100010219094341");
            gids.Add("030000050310180911");
            gids.Add("201706260157165");
            gids.Add("201706300150728");

            var glist3 = giftopt.Search().Where(b => b.Giftid.In(gids)).ToList();


            #region where

            //不支持
            DBUserPointRepository tb_UserpointRepository = new DBUserPointRepository();

            var upWhere1 = tb_UserpointRepository.Search();

            var w1 = upWhere1.Where(b => b.Uid == "sss");

            var w2 = w1.Where(b => b.Points > 0);

            var up1 = upWhere1.First();

            //支持
            Expression <Func <DBUserPoint, bool> > eWhere1 = null;

            if (true)
            {
                eWhere1 = (b => b.Uid.IsNotNull());
            }

            Expression <Func <DBUserPoint, bool> > eWhere2 = (b => b.Points > 0);

            if (true)
            {
                eWhere2 = (b => b.Points > 0);
            }

            Expression <Func <DBUserPoint, bool> > eWhere3 = null;

            if (false)
            {
                eWhere3 = (b => b.Uid.Contains("1"));
            }


            var upWhere2 = tb_UserpointRepository.Search().Where(eWhere1, eWhere2, eWhere3).ToList();


            //tb_UserpointRepository.Search().OrderBy()


            //Where条件拼接一:

            var dbTaskRepository = new DBTaskRepository();

            var where1 = new Where <DBTask>();
            where1.And(d => d.Operator != "");
            where1.And(d => d.Totallimit >= 0);

            var list1 = dbTaskRepository.Search()
                        .Where(where1)
                        .Page(1, 2)
                        .ToList();

            var list2 = dbTaskRepository.Search()
                        .Where(where1)
                        .Page(2, 2)
                        .ToList();

            //多表条件拼接

            //var where2 = new Where<table>();
            //where2.And(a => a.id == 1);
            //where2.And<table2>((a, b) => b.id == 2);
            //where2.And<table3>((a, c) => c.id == 3);

            //var list2 = new DBContext().Search<table>()
            //                .InnerJoin<table2>((a, b) => a.id == b.aid)
            //                .InnerJoin<table3>((a, c) => a.id == c.aid)
            //                .Where(where1)
            //                .ToList();

            //上面的where还可以这样写:
            //var where3 = new Where<table>();
            //where3.And<table2, table3>((a, b, c) => a.id == 1 && b.id == 2 && c.id == 3);

            #endregion


            var plist = tb_UserpointRepository.GetList(1, 100);

            #region mysql

            DBTaskRepository repository = new DBTaskRepository();

            var task = repository.GetList(1, 10);

            //var taskModel = task.ConvertTo<TaskModel>();

            #endregion


            #region 无实体sql操作,自定义参数

            var dt1 = new DBContext().FromSql("select * from tb_task where taskid=@taskID").AddInParameter("@taskID", System.Data.DbType.String, 200, "10B676E5BC852464DE0533C5610ACC53").ToFirst <DBTask>();

            var count = new DBContext().Search <DBTask>().Where(b => b.Crc32.Avg() > 1).Where(" 1=1 ").Count();

            //dbContext.ExecuteNonQuery("");

            //dbContext.FromSql("").ToList<DBTask>();

            #endregion


            string result = string.Empty;

            var entity = new Models.ArticleKind();

            var entityRepository = new Models.ArticleKindRepository();

            var pagedList = entityRepository.Search(entity).GetPagedList(1, 100, "ID", true);

            do
            {
                Test2();

                Console.WriteLine("输入R继续,其他键退出");
                result = Console.ReadLine();
            }while (result.ToUpper() == "R");
        }
示例#2
0
        static void Main(string[] args)
        {
            var db = new DBContext();

            var dt = db.FromSql("select * from tb_task").ToDataTable();

            var dttasks = dt.DataTableToEntityList <DBTask>();

            var taskModel = new TaskModel()
            {
                Crc32        = 123,
                TaskID       = Guid.NewGuid().ToString("N"),
                BeginTime    = DateTime.Now,
                BusinID      = "asdfead24545",
                CompanyId    = "54",
                CreateTime   = DateTime.Now,
                DayLimit     = 10,
                DayTimes     = 100,
                Description  = "adsfevadsfasdfsadf",
                EndTime      = DateTime.Now,
                FlowType     = "5687653",
                IsDel        = false,
                IsEnabled    = true,
                Name         = "afeadfad545646546",
                Operator     = "5435635321",
                PlatformID   = "8423416534635",
                Point        = 2,
                TaskMaxPoint = 100,
                TaskType     = 3
            };

            var tn = taskModel.ConvertTo <DBTask>();

            var taa = taskModel.ConvertTo <TestA>();

            var aa = new TestA()
            {
                aa  = DateTime.Now,
                Age = 10,
                //Created = "2019-04-22 22:53",
                id   = "100001",
                Num  = 10.235M,
                Num1 = 100
            };

            var bb = aa.ConvertTo <TestB>();

            var cc = bb.ConvertTo <TestA>();

            Console.WriteLine("WEF使用实例");

            Console.WriteLine("-----------------------------");

            var giftopt = new DBGiftRepository();

            var giftwhere = giftopt.Search().Where(b => b.Giftid.Contains("1"));

            giftwhere = giftwhere.Where(b => !b.Isdel && b.Isenabled); //不能连接


            giftwhere = giftwhere.OrderBy(b => b.Createtime).OrderByDescending(b => b.Giftid);//不能连接

            var glist = giftwhere.ToList();

            var glist2 = giftopt.Search().Where(b => b.Giftid.Like("1")).ToList();

            var giftids = giftopt.Search().Page(1, 10).ToList().Select(b => b.Giftid).ToList();

            var sum = giftopt.Search().Select(b => b.Supporttype.Sum()).ToFirstDefault().Supporttype;

            var avg = giftopt.Search().Select(b => b.Supporttype.Avg()).ToFirstDefault().Supporttype;

            var glist22 = giftopt.Search().Where(b => b.Giftid.In(giftids)).ToList();

            var gids = new List <string>();

            gids.Add("120100010219094341");
            gids.Add("030000050310180911");
            gids.Add("201706260157165");
            gids.Add("201706300150728");

            var glist3 = giftopt.Search().Where(b => b.Giftid.In(gids)).ToList();


            #region where

            //不支持
            DBUserPointRepository tb_UserpointRepository = new DBUserPointRepository();

            var upWhere1 = tb_UserpointRepository.Search();

            upWhere1 = upWhere1.Where(b => b.Uid == "sss");

            upWhere1 = upWhere1.Where(b => b.Points > 0);

            var up1 = upWhere1.First();

            //支持
            Expression <Func <DBUserPoint, bool> > eWhere1 = null;

            if (true)
            {
                eWhere1 = (b => b.Uid.IsNotNull());
            }

            Expression <Func <DBUserPoint, bool> > eWhere2 = (b => b.Points > 0);

            if (true)
            {
                eWhere2 = (b => b.Points > 0);
            }

            Expression <Func <DBUserPoint, bool> > eWhere3 = null;

            if (false)
            {
                eWhere3 = (b => b.Uid.Contains("1"));
            }


            var upWhere2 = tb_UserpointRepository.Search().Where(eWhere1, eWhere2, eWhere3);

            var up2 = upWhere2.ToList();

            #endregion


            var plist = tb_UserpointRepository.GetList(1, 100);

            #region mysql

            DBTaskRepository repository = new DBTaskRepository();

            var task = repository.GetList(1, 10);

            //var taskModel = task.ConvertTo<TaskModel>();

            #endregion


            #region 无实体sql操作,自定义参数

            var dt1 = DBContext.Default.FromSql("select * from tb_task where taskid=@taskID").AddInParameter("@taskID", System.Data.DbType.String, 200, "10B676E5BC852464DE0533C5610ACC53").ToFirst <DBTask>();

            var count = DBContext.Default.Search <DBTask>().Where(b => b.Crc32.Avg() > 1).Where(" 1=1 ").Count();

            //dbContext.ExecuteNonQuery("");

            //dbContext.FromSql("").ToList<DBTask>();

            #endregion


            string result = string.Empty;

            var entity = new Models.ArticleKind();

            var entityRepository = new Models.ArticleKindRepository();

            var pagedList = entityRepository.Search(entity).GetPagedList(1, 100, "ID", true);

            do
            {
                Test2();

                Console.WriteLine("输入R继续,其他键退出");
                result = Console.ReadLine();
            }while (result.ToUpper() == "R");
        }
示例#3
0
 /// <summary>
 /// 删除实体
 /// <param name="obj">传进的实体</param>
 /// </summary>
 public int Delete(ArticleKind obj)
 {
     obj.Attach(EntityState.Deleted);
     return(db.Save(obj));
     //return db.Delete(obj);
 }
示例#4
0
 /// <summary>
 /// 更新实体
 /// <param name="obj">传进的实体</param>
 /// </summary>
 public int Update(ArticleKind obj)
 {
     return(db.Update(obj));
 }
示例#5
0
 /// <summary>
 /// 添加实体
 /// <param name="obj">传进的实体</param>
 /// </summary>
 public int Insert(ArticleKind obj)
 {
     return(db.Insert(obj));
 }
示例#6
0
 /// <summary>
 /// 当前实体查询上下文
 /// </summary>
 public ISearch <ArticleKind> Search(ArticleKind entity)
 {
     return(db.Search <ArticleKind>(entity));
 }
示例#7
0
 /// <summary>
 /// 删除实体
 /// <param name="obj">传进的实体</param>
 /// </summary>
 public int Delete(ArticleKind obj)
 {
     return(db.Delete(obj));
 }