Beispiel #1
0
        static void Main()
        {
            var context = new SupermarketChainEntities();
            var vendors = context.Vendors
                .OrderBy(v => v.VendorName)
                .Select(v => new
                {
                    v.VendorName,
                    Products = v.Products
                        .OrderBy(p => p.ProductName)
                        .Select(p => p.ProductName)
                });

            var xmlreport = new XElement("report");
            foreach (var vendor in vendors)
            {
                var xmlvendor = new XElement("vendor");
                xmlvendor.Add(new XAttribute("name", vendor.VendorName.Trim()));
                xmlreport.Add(xmlvendor);
                foreach (var product in vendor.Products)
                {
                    xmlvendor.Add(new XElement("product", product.Trim()));
                }
            }

            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var xmlDocument = new XDocument(xmlreport);
            xmlDocument.Save(path + "\\report.xml");
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     var context = new SupermarketChainEntities();
     var product = from vendor in context.Vendors
                   where vendor.VendorName == "Coca-Cola"
         select vendor.VendorName;
     foreach (var p in product)
     {
         Console.WriteLine(p);
     }
 }
        private static void AddVendorExpense(string vendorName, DateTime expenseDate, decimal expenseAmount)
        {
            var context = new SupermarketChainEntities();
            var vendorId = context.Vendors
                .Where(v => v.VendorName.Trim() == vendorName)
                .Select(v => v.Id).First();

            Expense expenseEntity = new Expense();
            expenseEntity.VdendorId = vendorId;
            expenseEntity.Date = expenseDate;
            expenseEntity.Amount = expenseAmount;
            context.Expenses.Add(expenseEntity);
            context.SaveChanges();
            Console.WriteLine("Added expense for vendor: {0}", vendorName);
        }