private void btnDeleteWithSearch_Click(object sender, EventArgs e) { using (var db = new EntityFrameworkPlusDbContext()) { var unitPrice = Convert.ToDecimal(txtUnitPrice.Text); // ReSharper disable once NotAccessedVariable Expression <Func <GoodsModel, bool> > whereExpression = null; if (cbxOperation.Text.Equals("=")) { whereExpression = d => d.UnitPrice == unitPrice; } if (cbxOperation.Text.Equals(">=")) { whereExpression = d => d.UnitPrice >= unitPrice; } if (cbxOperation.Text.Equals(">")) { whereExpression = d => d.UnitPrice > unitPrice; } if (cbxOperation.Text.Equals("<=")) { whereExpression = d => d.UnitPrice <= unitPrice; } if (cbxOperation.Text.Equals("<")) { whereExpression = d => d.UnitPrice < unitPrice; } db.Goodses.Where(whereExpression).Delete(); } SearchGood(); }
public void SearchGood() { using (var db = new EntityFrameworkPlusDbContext()) { dgvList.DataSource = db.Goodses.ToList(); } }
private void btnSearch_Click(object sender, EventArgs e) { using (var db = new EntityFrameworkPlusDbContext()) { var orders = db.Goodses.FromCache(); dgList.DataSource = null; dgList.DataSource = orders; } }
private static void FindGoodsMaxWithMinUnitPrice() { using (var dbContext = new EntityFrameworkPlusDbContext()) { var futureMaxGoodsUnitPrice = dbContext.Goodses.DeferredMax(g => g.UnitPrice).FutureValue <decimal>(); var futureMinGoodsUnitPrice = dbContext.Goodses.DeferredMin(g => g.UnitPrice).FutureValue <decimal>(); var maxGoodsUnitPrice = futureMaxGoodsUnitPrice.Value; var minGoodsUnitPrice = futureMaxGoodsUnitPrice.Value; } }
private static void FindOrdersWithGoodsies() { using (var dbContext = new EntityFrameworkPlusDbContext()) { var futureOrders = dbContext.Orders.Future(); var futureGoodsies = dbContext.Goodses.Future(); var orders = futureOrders.ToList(); var goodsies = futureGoodsies.ToList(); } }
private void btnSearch_Click(object sender, EventArgs e) { using (var db = new EntityFrameworkPlusDbContext()) { var second = Convert.ToDouble(txtAbsoluteExpiration.Text.Trim()); var absoluteExpirationSecond = DateTime.Now.AddSeconds(second); var orders = db.Goodses.FromCache(absoluteExpirationSecond); dgList.DataSource = null; dgList.DataSource = orders; } }
private void btnUpdateWithSearch_Click(object sender, EventArgs e) { var creator = txtCreator.Text.Trim(); var unitPrice = Convert.ToDecimal(txtUnitPrice.Text.Trim()); using (var db = new EntityFrameworkPlusDbContext()) { db.Goodses.Where(c => c.Creator.Equals(creator)).Update(c => new GoodsModel { UnitPrice = unitPrice }); } SearchGood(); }
public static void DeleteOrder() { using (var dbContext = new EntityFrameworkPlusDbContext()) { var audit = new Audit { CreatedBy = "david" }; var orderAsync = dbContext.Orders.FirstAsync(); var order = orderAsync.Result; dbContext.Entry(order).State = EntityState.Deleted; dbContext.SaveChanges(audit); } }
private void btnSearch_Click(object sender, EventArgs e) { using (var db = new EntityFrameworkPlusDbContext()) { var second = Convert.ToDouble(txtSlidingExpiration.Text.Trim()); var options = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromSeconds(second) }; var orders = db.Goodses.FromCache(options); dgList.DataSource = null; dgList.DataSource = orders; } }
private static IEnumerable <OrderModel> FindPagerOrders(int pageSize, int pageIndex, out int totalCount) { using (var dbContext = new EntityFrameworkPlusDbContext()) { var orders = dbContext.Orders.OrderBy(o => o.CreateDateTime); var futureCount = orders.DeferredCount().FutureValue(); var futurePagerOrders = orders.Skip((pageIndex - 1) * pageSize).Take(pageSize).Future(); totalCount = futureCount.Value; return(futurePagerOrders.ToList()); } }
public static void UpdateOrder() { using (var dbContext = new EntityFrameworkPlusDbContext()) { var audit = new Audit { CreatedBy = "david" }; var orderAsync = dbContext.Orders.FirstAsync(); var order = orderAsync.Result; order.LastModifier = "davidzhou"; order.LastModifiedDateTime = DateTime.Now; order.OrderStatus = "已完成"; dbContext.Entry(order); dbContext.SaveChanges(audit); } }
public static void AddOrder() { using (var dbContext = new EntityFrameworkPlusDbContext()) { var audit = new Audit { CreatedBy = "david" }; dbContext.Orders.Add(new OrderModel { OrderNo = "ORDER0001", OrderCreator = "david", OrderDateTime = DateTime.Now, OrderStatus = "已出库", Creator = "david", CreateDateTime = DateTime.Now }); dbContext.SaveChanges(audit); } }