private static void FillMyProducts(List <MyProduct> myProducts)
 {
     using (LINQToSQLDataContext db = new LINQToSQLDataContext())
     {
         Table <Product> productTable = db.GetTable <Product>();
         List <Product>  products     = (from product in productTable
                                         select product).Take(100).ToList();
         string[] countries = { "Poland", "Germany", "USA" };
         Random   random    = new Random();
         foreach (Product p in products)
         {
             myProducts.Add(new MyProduct(p, countries[random.Next(0, countries.Length)]));
         }
     }
 }
 public void GetProductAndVendorNamesTest()
 {
     using (LINQToSQLDataContext db = new LINQToSQLDataContext())
     {
         Table <Product> productTable = db.GetTable <Product>();
         List <Product>  allProducts  = (from product in productTable
                                         select product).ToList();
         string result = allProducts.GetProductAndVendorNames();
         Assert.AreEqual(460, result.Split(new[] { Environment.NewLine },
                                           StringSplitOptions.None).Length);
         Assert.AreEqual("Adjustable Race - Litware, Inc.", result.Split(new[] { Environment.NewLine },
                                                                         StringSplitOptions.None).First());
         Assert.AreEqual("Chain - Varsity Sport Co.", result.Split(new[] { Environment.NewLine },
                                                                   StringSplitOptions.None).Last());
     }
 }
Example #3
0
        public static string GetProductAndVendorNames(this List <Product> products)
        {
            using (LINQToSQLDataContext db = new LINQToSQLDataContext())
            {
                Table <ProductVendor> productVendorTable = db.GetTable <ProductVendor>();
                List <ProductVendor>  productVendorAll   = (from productVendor in productVendorTable
                                                            select productVendor).ToList();

                var query = from p in products
                            from pv in productVendorAll
                            where p.ProductID == pv.ProductID
                            select new
                {
                    ProductName = p.Name,
                    VendorName  = pv.Vendor.Name
                };

                return(String.Join(Environment.NewLine, (from q in query
                                                         select q.ProductName + " - " + q.VendorName).ToList()));
            }
        }
Example #4
0
 public DepartmentRepository()
 {
     dataContext         = new LINQToSQLDataContext();
     departments         = dataContext.GetTable <Department>();
     employeeDepartments = dataContext.GetTable <EmployeeDepartmentHistory>();
 }