protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Exemplo n.º 2
0
        public void ProductsReplacement()
        {
            LinqToDB.Common.Configuration.Linq.AllowMultipleQuery = true;

            var db = new NorthwindDB("Northwind");

            var orders = db.OrderDetails.LoadWith(t => t.OrderDetailsOrder)
                         .Where(order => order.OrderDetailsOrder.ShippedDate == null)
                         .GroupBy(key => key.OrderID,
                                  (i, detailses) => new
            {
                OrderID   = i,
                PrductIDs = detailses.Where(item => item.OrderID == i).Select(item => item.ProductID).ToList()
            }).ToList();

            db.Dispose();

            var rdm = new Random(DateTime.Now.Millisecond);

            using (db = new NorthwindDB("Northwind"))
            {
                foreach (var order in orders)
                {
                    int productid;
                    do
                    {
                        productid = rdm.Next(1, 77);
                    } while (order.PrductIDs.Contains(productid));

                    db.OrderDetails
                    .Where(item => item.OrderID == order.OrderID && item.ProductID == order.PrductIDs.First())
                    .Set(od => od.ProductID, productid)
                    .Set(od => od.Discount, (float)0.99)
                    .Update();
                }
            }
        }
Exemplo n.º 3
0
 public void Cleanup()
 {
     nw.Dispose();
 }