예제 #1
0
        public static void delete(T table)
        {
            var sessionFactory = MySQLSessionFactory.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    session.Delete(table);
                    transaction.Commit();
                }
            }
        }
예제 #2
0
        public static List <T> all()
        {
            var sessionFactory = MySQLSessionFactory.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    return((List <T>)session.CreateCriteria(typeof(T))
                           .List <T>());
                }
            }
        }
예제 #3
0
        public static object query(string query)
        {
            object result = null;

            var sessionFactory = MySQLSessionFactory.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    result = session.CreateSQLQuery(query).UniqueResult();
                    transaction.Commit();
                }
            }

            return(result);
        }
예제 #4
0
        public static void truncate()
        {
            var sessionFactory = MySQLSessionFactory.CreateSessionFactory();
            var metadata       = sessionFactory.GetClassMetadata(typeof(T))
                                 as NHibernate.Persister.Entity.AbstractEntityPersister;
            string table = metadata.TableName;

            using (ISession session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    string deleteAll = string.Format("DELETE FROM {0}", table);
                    session.CreateSQLQuery(deleteAll).ExecuteUpdate();

                    transaction.Commit();
                }
            }
        }