/// <summary>
 /// Create a new OrderDetails object.
 /// </summary>
 /// <param name="orderID">Initial value of the OrderID property.</param>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="unitPrice">Initial value of the UnitPrice property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="discount">Initial value of the Discount property.</param>
 public static OrderDetails CreateOrderDetails(global::System.Int64 orderID, global::System.Int64 productID, global::System.Decimal unitPrice, global::System.Int16 quantity, global::System.Single discount)
 {
     OrderDetails orderDetails = new OrderDetails();
     orderDetails.OrderID = orderID;
     orderDetails.ProductID = productID;
     orderDetails.UnitPrice = unitPrice;
     orderDetails.Quantity = quantity;
     orderDetails.Discount = discount;
     return orderDetails;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the OrderDetails EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrderDetails(OrderDetails orderDetails)
 {
     base.AddObject("OrderDetails", orderDetails);
 }
Exemple #3
0
      private static int ComplexPrimaryKeyTest()
      {
          using (northwindEFEntities db = new northwindEFEntities())
          {
              long orderId = 10248;
              long productId = 1;
              int[] counts = { 0, 0 };

              //
              // NOTE: *REQUIRED* This is required so that the
              //       Entity Framework is prevented from opening
              //       multiple connections to the underlying SQLite
              //       database (i.e. which would result in multiple
              //       IMMEDIATE transactions, thereby failing [later
              //       on] with locking errors).
              //
              db.Connection.Open();

              KeyValuePair<string, object> orderIdPair =
                  new KeyValuePair<string, object>("OrderID", orderId);

              KeyValuePair<string, object> productIdPair =
                  new KeyValuePair<string, object>("ProductID", productId);

              /////////////////////////////////////////////////////////////////

              OrderDetails newOrderDetails = new OrderDetails();

              newOrderDetails.OrderID = orderId;
              newOrderDetails.ProductID = productId;
              newOrderDetails.UnitPrice = (decimal)1.23;
              newOrderDetails.Quantity = 1;
              newOrderDetails.Discount = 0.0f;

              newOrderDetails.OrdersReference.EntityKey = new EntityKey(
                  "northwindEFEntities.Orders",
                  new KeyValuePair<string, object>[] { orderIdPair });

              newOrderDetails.ProductsReference.EntityKey = new EntityKey(
                  "northwindEFEntities.Products",
                  new KeyValuePair<string, object>[] { productIdPair });

              db.AddObject("OrderDetails", newOrderDetails);

              try
              {
                  db.SaveChanges();
                  counts[0]++;
              }
              catch (Exception e)
              {
                  Console.WriteLine(e);
              }
              finally
              {
                  db.AcceptAllChanges();
              }

              try
              {
                  db.Refresh(RefreshMode.StoreWins, newOrderDetails);
                  counts[0]++;
              }
              catch (Exception e)
              {
                  Console.WriteLine(e);
              }

              Console.WriteLine("inserted {0}", counts[0]);

              /////////////////////////////////////////////////////////////////

              newOrderDetails.UnitPrice = (decimal)2.34;
              newOrderDetails.Quantity = 2;
              newOrderDetails.Discount = 0.1f;

              try
              {
                  db.SaveChanges();
                  counts[1]++;
              }
              catch (Exception e)
              {
                  Console.WriteLine(e);
              }
              finally
              {
                  db.AcceptAllChanges();
              }

              try
              {
                  db.Refresh(RefreshMode.StoreWins, newOrderDetails);
                  counts[1]++;
              }
              catch (Exception e)
              {
                  Console.WriteLine(e);
              }

              Console.WriteLine("updated {0}", counts[1]);
          }

          return 0;
      }