Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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();
        }