Пример #1
0
        public static void DisplayAllTeachers()
        {
            ISession session = NHibernateHelper.GetCurrentSession();

            try
            {
                using (var tx = session.BeginTransaction())
                {
                    var teachers = session.CreateCriteria <Teacher>().List <Teacher>();

                    foreach (var teacher in teachers)
                    {
                        Console.WriteLine("{0} \t{1}, \t{2}", teacher.ID, teacher.FirstName, teacher.LastName);
                    }
                    tx.Commit();
                }
                Console.ReadLine();
            }
            finally
            {
                NHibernateHelper.CloseCurrentSession();
            }
        }
Пример #2
0
        public static bool DeleteUser(int id)
        {
            ISession session = NHibernateHelper.GetCurrentSession();

            try
            {
                using (var tx = session.BeginTransaction())
                {
                    var stdnt = session.Get <Student>(id);

                    if (stdnt == null)
                    {
                        Console.WriteLine("Theres not user with that ID, try again!");
                        return(false);
                    }

                    Console.WriteLine("Retrieved by ID");
                    Console.WriteLine("{0} \t{1},\t{2}", stdnt.ID, stdnt.FirstName,
                                      stdnt.LastName);

                    Console.WriteLine("\nFetch the complete list of again? Y/N");
                    string entireList = Console.ReadLine();

                    tx.Commit();
                    if (entireList == "Y".ToLower())
                    {
                        DisplayAllStudents();
                    }
                    return(true);
                }
            }
            finally
            {
                NHibernateHelper.CloseCurrentSession();
            }
        }