static void Update() { Console.WriteLine("Updating"); var session = SessionManager.OpenSession(); var hasUsers = session.Query <User>().Any(); if (!hasUsers) { Console.WriteLine("No users found!"); return; } var users = session.Query <User>().ToList(); var seed = users.Max(u => u.Id) + 1; foreach (var user in users) { user.DateUpdated = DateTime.Now; User.PopulateAllProperties(seed, user); seed++; } using (var transaction = session.BeginTransaction()) { users.ForEach(session.Update); transaction.Commit(); } }
static void Update() { Console.WriteLine("Updating"); var session = SessionManager.OpenSession(); var hasUsers = session.Users.Any(); if (!hasUsers) { Console.WriteLine("No users found!"); return; } var users = session.Users.ToList(); var seed = users.Max(u => u.Id) + 1; foreach (var user in users) { user.DateUpdated = DateTime.Now; User.PopulateAllProperties(seed, user); seed++; } session.SaveChanges(); }
static void Create() { Console.WriteLine("Creating"); var session = SessionManager.OpenSession(); var hasUsers = session.Query <User>().Any(); if (hasUsers) { Console.WriteLine("Users table is not empty!"); return; } var users = new List <User>(); for (int i = 0; i < 10; i = i + 2) { var id = i + 1; var user = new User { DateCreated = DateTime.Now }; User.PopulateAllProperties(id, user); users.Add(user); id++; user = new User { DateCreated = DateTime.Now }; User.PopulateRequiredProperties(id, user); users.Add(user); } using (var transaction = session.BeginTransaction()) { users.ForEach(user => session.Save(user)); transaction.Commit(); } }
static void Create() { Console.WriteLine("Creating"); var session = SessionManager.OpenSession(); var hasUsers = session.Users.Any(); if (hasUsers) { Console.WriteLine("Users table is not empty!"); return; } var users = new List <User>(); for (int i = 0; i < 10; i = i + 2) { var id = i + 1; var user = new User { DateCreated = DateTime.Now }; User.PopulateAllProperties(id, user); users.Add(user); id++; user = new User { DateCreated = DateTime.Now }; User.PopulateRequiredProperties(id, user); users.Add(user); } users.ForEach(session.Add); session.SaveChanges(); }