private void TestProductSaleByDayAdd() { var addEntity = new ProductSaleByDayEntity() { SysNo = Guid.NewGuid(), DataSource = "测试来源", ProductID = Guid.NewGuid(), ShopID = Guid.NewGuid(), ShopName = "测试店铺添加", ProductName = "测试商品", OutProductID = Guid.NewGuid().ToString(), ImportGroupId = Guid.NewGuid(), StatisticalDate = DateTime.Now.AddYears(2019 - DateTime.Now.Year)//分库分表字段是必须的 }; var repository = GetRepository(); //如果新增主键是自增列会自动赋值自增列值到主键 repository.Add(addEntity); var entity = repository.Get(new ProductSaleByDayEntity { DBModel_ShuffledTempDate = addEntity.StatisticalDate, SysNo = addEntity.SysNo }); Assert.NotNull(entity); Assert.AreEqual(addEntity.SysNo, entity.SysNo); Assert.AreEqual(addEntity.ShopName, entity.ShopName); }
public string Index() { if (isRuning == true) { return("正在运行中"); } lock (lockObj) { isRuning = true; try { var repositoryFactory = RepositoryFactory.Create <ProductSaleByDayEntity>(); var query = QueryFactory.Create <ProductSaleByDayEntity>(m => m.CreateDate > DateTime.Now.Date); query.DBModel.DBModel_ShuffledTempDate = new DateTime(2019, 09, 01); if (repositoryFactory.GetList(query).Count > 10) { return(""); } var importGroupId = Guid.NewGuid(); var random = new Random(); var tempDate = new DateTime(2018, 1, 1); while (tempDate <= new DateTime(2019, 12, 31)) { if (tempDate.Day == 1) { query = QueryFactory.Create <ProductSaleByDayEntity>(); query.DBModel.DBModel_ShuffledTempDate = tempDate; repositoryFactory.Delete(query); } foreach (var p in dicProduct) { var temp = new ProductSaleByDayEntity(); temp.SysNo = Guid.NewGuid(); temp.DataSource = lstDataSource[random.Next(lstDataSource.Count)]; temp.ShopName = "测试店铺"; temp.ProductID = p.Key; temp.OutProductID = p.Value; temp.ProductName = p.Value; temp.Sales = random.Next(100000); temp.StatisticalDate = tempDate; temp.UpdateDate = temp.CreateDate = DateTime.Now; temp.UpdateUserID = temp.CreateUserID = Guid.NewGuid(); temp.ImportGroupId = importGroupId; repositoryFactory.Add(temp); } tempDate = tempDate.AddDays(1); } } finally { isRuning = false; } return("初始化成功"); } }
public bool Delete() { var deleteEntity = new ProductSaleByDayEntity() { SysNo = Guid.Parse("650BC09C-2B9C-467B-A457-8B4853CC1F0F"), DBModel_ShuffledTempDate = new DateTime(2019, 01, 05),//对于分库分表来说DBModel_ShuffledTempDate是必须的用来确认是那个库表 }; var repository = GetRepository(); return(repository.Delete(deleteEntity)); }
public int UpdateWhere() { var updateEntity = new ProductSaleByDayEntity() { DataSource = "测试来源修改", ShopName = "店铺修改Where", DBModel_ShuffledTempDate = new DateTime(2019, 01, 05),//如果用这句话来确定是那个库及表 // StatisticalDate = statisticalDate,//如果要更新StatisticalDate则可以用这句话替代上面那句话 }; var repository = GetRepository(); var where = QueryFactory.Create <ProductSaleByDayEntity>(m => m.ShopName == "测试店铺1" && m.StatisticalDate > new DateTime(2019, 01, 03));//where是更新条件 //注意如果是更新用的是实体类的DBModel_ShuffledTempDate Query中的无效 return(repository.Update(updateEntity, where)); }
public bool Update() { var updateEntity = new ProductSaleByDayEntity() { SysNo = Guid.Parse("650BC09C-2B9C-467B-A457-8B4853CC1F0F"), DataSource = "测试来源修改", ShopName = "店铺修改", StatisticalDate = new DateTime(2019, 01, 05),//如果StatisticalDate赋值了则根据StatisticalDate找库表,然后根据主键更新,StatisticalDate也会被更新成所赋的值 //如果不想更新StatisticalDate可以用下面这句话 // DBModel_ShuffledTempDate=new DateTime(2019,01,05),//如果不想更新StatisticalDate字段则用这句话来确定是那个库及表 }; var repository = GetRepository(); //根据主键更新其他字段 return(repository.Update(updateEntity)); }
public void Add() { var addEntity = new ProductSaleByDayEntity() { SysNo = Guid.NewGuid(), DataSource = "测试来源", ProductID = Guid.NewGuid(), ShopID = Guid.NewGuid(), ShopName = "测试店铺", ProductName = "测试商品", OutProductID = Guid.NewGuid().ToString(), ImportGroupId = Guid.NewGuid(), StatisticalDate = DateTime.Now//分库分表字段是必须的 }; var repository = GetRepository(); //如果新增主键是自增列会自动赋值自增列值到主键 repository.Add(addEntity); }
public void TestProductSaleByDayUpdateWhere() { var repository = GetRepository(); var queryCount = QueryFactory.Create <ProductSaleByDayEntity>(m => !m.ProductName.Contains("没有") && m.ProductName.Contains("修改")); queryCount.DBModel.DBModel_ShuffledTempDate = new DateTime(2019, 01, 05); var count = repository.Count(queryCount); var updateEntity = new ProductSaleByDayEntity() { DataSource = "测试来源批量修改", ShopName = "店铺修改Where", DBModel_ShuffledTempDate = new DateTime(2019, 01, 05),//如果用这句话来确定是那个库及表 // StatisticalDate = statisticalDate,//如果要更新StatisticalDate则可以用这句话替代上面那句话 }; var where = QueryFactory.Create <ProductSaleByDayEntity>(m => !m.ProductName.Contains("没有") && m.ProductName.Contains("修改"));//where是更新条件 //注意如果是更新用的是实体类的DBModel_ShuffledTempDate Query中的无效 int updateCount = repository.Update(updateEntity, where); Assert.AreEqual(updateCount, count); Assert.AreNotEqual(updateCount, 0); }
public string Index() { var importGroupId = Guid.NewGuid(); var random = new Random(); var repositoryFactory = RepositoryFactory.Create <ProductSaleByDayEntity>(); var tempDate = new DateTime(2018, 1, 1); while (tempDate <= DateTime.Now.Date) { if (tempDate.Day == 1) { var query = QueryFactory.Create <ProductSaleByDayEntity>(); query.DBModel.DBModel_ShuffledTempDate = tempDate; repositoryFactory.Delete(query); } foreach (var p in dicProduct) { var temp = new ProductSaleByDayEntity(); temp.SysNo = Guid.NewGuid(); temp.DataSource = lstDataSource[random.Next(lstDataSource.Count)]; temp.ShopID = dicShop.Keys.ToList()[random.Next(dicShop.Count)]; temp.ShopName = dicShop[temp.ShopID]; temp.ProductID = p.Key; temp.OutProductID = p.Value; temp.ProductName = p.Value; temp.Sales = random.Next(100000); temp.StatisticalDate = tempDate; temp.UpdateDate = temp.CreateDate = DateTime.Now; temp.UpdateUserID = temp.CreateUserID = Guid.NewGuid(); temp.ImportGroupId = importGroupId; repositoryFactory.Add(temp); } tempDate = tempDate.AddDays(1); } return("初始化成功"); }
public string Index() { if (isRuning == true) { return("正在运行中"); } lock (lockObj) { isRuning = true; try { var shopRepository = RepositoryFactory.Create <ShopEntity>(); shopRepository.Delete(QueryFactory.Create <ShopEntity>()); for (int i = 0; i < 10; i++) { var shop = new ShopEntity { SysNo = Guid.NewGuid(), ShopCode = "00" + i, ShopName = "测试店铺" + i, ShopType = i % 3 }; shopRepository.Add(shop); } lstShop = shopRepository.GetList(QueryFactory.Create <ShopEntity>()); var importGroupId = Guid.NewGuid(); var random = new Random(); var repositoryFactory = RepositoryFactory.Create <ProductSaleByDayEntity>(); var repositoryNSFactory = RepositoryFactory.Create <ProductSaleByDayNSEntity>(); repositoryNSFactory.Delete(QueryFactory.Create <ProductSaleByDayNSEntity>()); var tempDate = new DateTime(2018, 1, 1); while (tempDate <= DateTime.Now.Date) { if (tempDate.Day == 1) { var query = QueryFactory.Create <ProductSaleByDayEntity>(); query.DBModel.DBModel_ShuffledTempDate = tempDate; repositoryFactory.Delete(query); } foreach (var p in dicProduct) { var temp = new ProductSaleByDayEntity(); var tempNS = new ProductSaleByDayNSEntity(); tempNS.SysNo = temp.SysNo = Guid.NewGuid(); tempNS.DataSource = temp.DataSource = lstDataSource[random.Next(lstDataSource.Count)]; var shop = lstShop[random.Next(lstShop.Count)]; tempNS.ShopID = temp.ShopID = shop.SysNo; temp.ShopName = shop.ShopName; tempNS.ProductID = temp.ProductID = p.Key; tempNS.OutProductID = temp.OutProductID = p.Value; tempNS.ProductName = temp.ProductName = p.Value; tempNS.Sales = temp.Sales = random.Next(100000); tempNS.StatisticalDate = temp.StatisticalDate = tempDate; tempNS.UpdateDate = temp.UpdateDate = temp.CreateDate = DateTime.Now; tempNS.UpdateUserID = temp.UpdateUserID = temp.CreateUserID = Guid.NewGuid(); tempNS.ImportGroupId = temp.ImportGroupId = importGroupId; repositoryFactory.Add(temp); repositoryNSFactory.Add(tempNS); } tempDate = tempDate.AddDays(1); } } finally { isRuning = false; } return("初始化成功"); } }