private static void ReplicateExpenses(IQueryable<Expense> expenses, MySQLContext context)
        {
            foreach (var expense in expenses)
            {
                if (!context.Expenses.Any(e => e.ExpenseDate == expense.ExpenseDate && e.Vendor.Name == expense.Vendor.Name))
                {
                    var newExpense = new Expense()
                    {
                        VendorId = expense.Vendor.Id,
                        ExpenseDate = expense.ExpenseDate,
                        ExpenseSum = expense.ExpenseSum
                    };

                    context.Expenses.Add(newExpense);

                    context.SaveChanges();
                }
            }
        }
        public static void ReadExpensesFile(string filename = "Vendors-Expenses.xml")
        {
            XDocument xmlDoc = XDocument.Load(filename);
            var salesData =
                from sales in xmlDoc.Descendants("sale")
                select new
                {
                    Vendor = sales.Attribute("vendor").Value,
                    Expenses = from expenses in sales.Elements("expenses")
                               select new
                               {
                                   Date = expenses.Attribute("month").Value,
                                   Sum = expenses.Value
                               }
                };

            //Console.WriteLine("Found {0} sales:", salesData.Count());
            //foreach (var item in salesData)
            //{
            //    Console.WriteLine("Vendor: " + item.Vendor);
            //    foreach (var exp in item.Expenses)
            //    {
            //        Console.WriteLine("Date: {0}, Sum: {1}", exp.Date, exp.Sum);
            //    }
            //}

            if (salesData != null && salesData.Count() > 0)
            {
                using (var sqlContext = new SupermarketEntities())
                {
                    foreach (var sale in salesData)
                    {
                        using (var scope = new System.Transactions.TransactionScope())
                        {
                            var vendor = sqlContext.Vendors.Where(v => v.Name == sale.Vendor).ToList();
                            if (vendor.Count == 0)
                            {
                                var newVendor = new Vendor();
                                newVendor.Name = sale.Vendor;

                                sqlContext.Vendors.Add(newVendor);
                                // sqlContext.SaveChanges();
                                vendor.Add(newVendor);
                            }

                            foreach (var exp in sale.Expenses)
                            {
                                var expense = new Expense();
                                expense.VendorId = vendor[0].Id;
                                expense.Value = decimal.Parse(exp.Sum);
                                expense.Month = DateTime.Parse("1-" + exp.Date);
                                if (sqlContext.Expenses.Where(
                                    e => e.Month == expense.Month && e.VendorId==expense.VendorId).Count() == 0)
                                {
                                    sqlContext.Expenses.Add(expense);
                                }
                            }

                            sqlContext.SaveChanges();
                            scope.Complete();
                        }
                    }
                }
            }
        }