Ejemplo n.º 1
0
 public IList <T> GetList()
 {
     using (ISession _session = NhibernateContext.SessionOpen())
     {
         return(_session.Query <T>().ToList());
     }
 }
Ejemplo n.º 2
0
        public EncurtadorFacadeService()
        {
            var session = NhibernateContext.GetSession();

            registroUrlRepository = new RegistroUrlRepository(session);
            unitOfWork            = new UnitOfWork(session);
        }
Ejemplo n.º 3
0
 public T GetById(int id)
 {
     using (ISession _session = NhibernateContext.SessionOpen())
     {
         return(_session.Get <T>(id));
     }
 }
Ejemplo n.º 4
0
        public IList <T> GetList(Expression <Func <T, bool> > predicate = null)
        {
            using (ISession _session = NhibernateContext.SessionOpen())
            {
                var list = _session.Query <T>()
                           .Where(predicate)
                           .ToList();

                return(list);
            }
        }
Ejemplo n.º 5
0
        public int GetCount(Expression <Func <T, bool> > predicate = null)
        {
            using (ISession _session = NhibernateContext.SessionOpen())
            {
                var count = _session.Query <T>()
                            .Where(predicate)
                            .Count();

                return(count);
            }
        }
Ejemplo n.º 6
0
        public IList <T> Get(
            out int total, out int totalDisplay,
            Expression <Func <T, bool> > filter = null,
            Func <IQueryable <T>, IOrderedQueryable <T> > orderBy = null,
            Expression <Func <T, T> > includeProperty             = null, Expression <Func <T, T> > thenInclude = null, int pageIndex = 1, int pageSize = 10)
        {
            using (ISession _session = NhibernateContext.SessionOpen())
            {
                var query = _session.Query <T>();

                total        = query.Count();
                totalDisplay = total;

                if (filter != null)
                {
                    query        = query.Where(filter);
                    totalDisplay = query.Count();
                }

                if (includeProperty != null)
                {
                    query = query.Fetch(includeProperty);
                }

                IQueryable <T> result = null;

                if (orderBy != null)
                {
                    result = orderBy(query).Skip((pageIndex - 1) * pageSize).Take(pageSize);
                }
                else
                {
                    result = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
                }

                return(result.ToList());
            }
        }
Ejemplo n.º 7
0
        public void Delete(T entity)
        {
            using (ISession _session = NhibernateContext.SessionOpen())
            {
                using (ITransaction _transaction = _session.BeginTransaction())
                {
                    try
                    {
                        _session.Delete(entity);
                        _transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        if (!_transaction.WasCommitted)
                        {
                            _transaction.Rollback();
                        }

                        throw new Exception(ex.Message);
                    }
                }
            }
        }