22 Apr 2011 @ 10:24 PM 

This is a simple and straightforward method I put in my base repositories to retrieve the row count of the results from an nhibernate criteria query.

protected int GetResultsCount(ICriteria criteria)
        {
            criteria.SetProjection(Projections.RowCount());
            var eventsCount = criteria.UniqueResult<int>();
            return eventsCount;
        }
Posted By: Boyd
Last Edit: 14 Apr 2011 @ 10:27 PM

EmailPermalinkComments Off
Tags
Tags: , ,
Categories: .Net, Programming
 20 Jan 2011 @ 11:07 AM 

Here is a quick general purpose nhibernate criteria call to retrieve a list of results where the id is in a list. It is written as a generic method that I placed in my base repository and can use it for all of my domain objects. So T resolves to the type of domain object you are retrieving.

        public IEnumerable<T> Get(IEnumerable<IdType> ids)
        {
            var criteria = Session.CreateCriteria<T>()
                .Add(Restrictions.In("Id", ids.ToArray()));

            return criteria.List<T>();
        }

The sql this generates is essentially:

select * from DomainObjectTable
where id in('id1', 'id2', ...)
Posted By: Boyd
Last Edit: 14 Apr 2011 @ 09:46 PM

EmailPermalinkComments Off
Tags
Tags: ,
Categories: .Net, Programming

 Last 50 Posts
Change Theme...
  • Users » 3
  • Posts/Pages » 30
  • Comments » 0
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

GeekPub



    No Child Pages.