/// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="productCode">Initial value of the ProductCode property.</param>
 public static Product CreateProduct(global::System.Int64 id, global::System.String name, global::System.String productCode)
 {
     Product product = new Product();
     product.ID = id;
     product.Name = name;
     product.ProductCode = productCode;
     return product;
 }
Example #2
0
 public void LoadNewProducts(string fileName, CancellationToken token)
 {
     using (DatabaseContext context = GetContext())
     {
         FileHelperAsyncEngine<CsvNewProduct> engine = new FileHelperAsyncEngine<CsvNewProduct>();
         engine.BeginReadFile(fileName);
         int i = 0;
         foreach (CsvNewProduct np in engine)
         {
             if (token.IsCancellationRequested) break;
             // check existence of the product
             // using its code
             Console.WriteLine("Checking product {0}...", np.ProductCode);
             if (!context.Products.Any((o) => o.ProductCode == np.ProductCode))
             {
                 Product p = new Product()
                 {
                     Name = np.ProductName,
                     ProductCode = np.ProductCode
                 };
                 context.AddToProducts(p);
                 Console.WriteLine("Added product {0}", np.ProductCode);
                 i++;
             }
         }
         engine.Close();
         if (i > 0) context.SaveChanges();
         Console.WriteLine("Added {0} new products", i);
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }