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); }
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(); }
public static void CreateUsers(ExpenseDatabaseContext context) { var user = new User() { Login = "******", Password = "******", UserGuid = Guid.NewGuid().ToString() }; context.Users.Add(user); }