コード例 #1
0
        public static void CreateExpenses(ExpenseDatabaseContext context)
        {
            var tag = new Tag()
                          {
                              Name = "food"
                          };
            context.Tags.Add(tag);

            var expense = new Expense.Expense();
            expense.Amount = 20;
            expense.DateOfMakingExpense = DateTime.UtcNow;
            expense.Description = "in the market";
            expense.Tag = tag;
            expense.User = context.Users.FirstOrDefault();
            context.Expenses.Add(expense);

            tag = new Tag()
                      {
                          Name = "party"
                      };
            context.Tags.Add(tag);

            expense = new Expense.Expense();
            expense.Amount = (Decimal)136.7;
            expense.DateOfMakingExpense = DateTime.UtcNow;
            expense.Description = "birthday";
            expense.Tag = tag;
            expense.User = context.Users.FirstOrDefault();
            context.Expenses.Add(expense);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                // drop exists database and create new
                System.Data.Entity.Database.SetInitializer(new DropCreateDatabaseAlways<ExpenseDatabaseContext>());

                using (var context = new ExpenseDatabaseContext())
                {
                    // create new user
                    UserCreator.CreateUsers(context);
                    context.SaveChanges();
                    //create new expense
                    ExpenseCreator.CreateExpenses(context);
                    context.SaveChanges();
                }

                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadKey();
        }
コード例 #3
0
 public static void CreateUsers(ExpenseDatabaseContext context)
 {
     var user = new User()
                        {
                            Login = "******",
                            Password = "******",
                            UserGuid = Guid.NewGuid().ToString()
                        };
         context.Users.Add(user);
 }