示例#1
0
        //Respositorio do Country
        public static void Create()
        {
            NhibernateHelper nh = new NhibernateHelper();

            using (var sf = nh.CreateSessionFactory())
            {
                sf.Close();
            }
        }
示例#2
0
        public static Country RetornarPaisesPorId(int id)
        {
            NhibernateHelper nh = new NhibernateHelper();

            using (var sf = nh.CreateSessionFactory())
                using (var session = sf.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        return(session.Get <Country>(id));
                    }
        }
示例#3
0
        public ActionResult <IEnumerable <User> > Get()
        {
            List <User> users;

            var sessionFactory = NhibernateHelper.CreateSessionFactory();

            using (ISession session = sessionFactory.OpenSession()) // Open a session to conect to the database
            {
                users = session.Query <User>().ToList();            //  Querying to get all the books
            }

            return(users);
        }
示例#4
0
        public static void AddProject(Country country)
        {
            NhibernateHelper nh = new NhibernateHelper();

            using (var sf = nh.CreateSessionFactory())
                using (var session = sf.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        try
                        {
                            session.SaveOrUpdate(country);
                            transaction.Commit();
                        }
                        catch (Exception e)
                        {
                            throw new Exception("Error ao criar" + e.Message);
                        }
                    }
        }