public ICollection <ProjJ> ReportAll <ProjJ>(string namedQuery, params Parameter[] parameters)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                IQuery query = RepositoryHelper <T> .CreateQuery(action.Value, namedQuery, parameters);

                return(query.List <ProjJ>());
            }
        }
        public ICollection <ProjT> ReportAll <ProjT>(DetachedCriteria criteria, ProjectionList projectionList)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, criteria, CreateCriteria);

                return(DoReportAll <ProjT>(crit, projectionList));
            }
        }
        public ICollection <ProjT> ReportAll <ProjT>(ProjectionList projectionList, Order[] orders, params ICriterion[] criteria)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .CreateCriteriaFromArray(action.Value, criteria, CreateCriteria, orders);

                return(DoReportAll <ProjT>(crit, projectionList));
            }
        }
        /// <summary>
        /// Loads all the entities that match the criteria
        /// by order
        /// </summary>
        /// <param name="orders">the order in which to bring the data</param>
        /// <param name="criteria">the criteria to look for</param>
        /// <returns>All the entities that match the criteria</returns>
        public ICollection <T> FindAll(Order[] orders, params ICriterion[] criteria)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .CreateCriteriaFromArray(action.Value, criteria, orders);

                return(crit.List <T>());
            }
        }
        public ICollection <ProjT> ReportAll <ProjT>(ProjectionList projectionList, bool distinctResults)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, null, CreateCriteria);

                return(DoReportAll <ProjT>(crit, projectionList, distinctResults));
            }
        }
        /// <summary>
        /// Find a single entity based on a named query.
        /// Thorws is there is more than one result.
        /// </summary>
        /// <param name="parameters">parameters for the query</param>
        /// <param name="namedQuery">the query to executre</param>
        /// <returns>The entity or null</returns>
        public T FindOne(string namedQuery, params Parameter[] parameters)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                IQuery query = RepositoryHelper <T> .CreateQuery(action.Value, namedQuery, parameters);

                return(query.UniqueResult <T>());
            }
        }
        /// <summary>
        /// Find a single entity based on a criteria.
        /// Thorws is there is more than one result.
        /// </summary>
        /// <param name="criteria">The criteria to look for</param>
        /// <returns>The entity or null</returns>
        public T FindOne(DetachedCriteria criteria)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit =
                    RepositoryHelper <T> .GetExecutableCriteria(action.Value, criteria, CreateCriteria);

                return(crit.UniqueResult <T>());
            }
        }
        /// <summary>
        /// Find a single entity based on a criteria.
        /// Thorws is there is more than one result.
        /// </summary>
        /// <param name="criteria">The criteria to look for</param>
        /// <returns>The entity or null</returns>
        public T FindOne(params ICriterion[] criteria)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit =
                    RepositoryHelper <T> .CreateCriteriaFromArray(action.Value, criteria);

                return(crit.UniqueResult <T>());
            }
        }
        /// <summary>
        /// Loads all the entities that match the criteria
        /// by order
        /// </summary>
        /// <param name="criteria">the criteria to look for</param>
        /// <param name="orders"> the order to load the entities</param>
        /// <returns>All the entities that match the criteria</returns>
        public ICollection <T> FindAll(DetachedCriteria criteria, params Order[] orders)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, criteria,
                                                                             CreateCriteria, orders);

                return(crit.List <T>());
            }
        }
        /// <summary>
        /// Counts the number of instances matching the criteria.
        /// </summary>
        public long Count(DetachedCriteria criteria)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, criteria, CreateCriteria);

                crit.SetProjection(Projections.RowCount());
                object countMayBe_Int32_Or_Int64_DependingOnDatabase = crit.UniqueResult();
                return(Convert.ToInt64(countMayBe_Int32_Or_Int64_DependingOnDatabase));
            }
        }
        /// <summary>
        /// Execute the named query and return paged results
        /// </summary>
        /// <param name="parameters">Parameters for the query</param>
        /// <param name="namedQuery">the query to execute</param>
        /// <param name="firstResult">The first result to return</param>
        /// <param name="numberOfResults">number of records to return</param>
        /// <returns>Paged results of the query</returns>
        public ICollection <T> FindAll(int firstResult, int numberOfResults, string namedQuery, params Parameter[] parameters)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                IQuery query = RepositoryHelper <T> .CreateQuery(action.Value, namedQuery, parameters);

                query.SetFirstResult(firstResult)
                .SetMaxResults(numberOfResults);
                return(query.List <T>());
            }
        }
        /// <summary>
        /// Find the entity based on a criteria.
        /// </summary>
        /// <param name="criteria">The criteria to look for</param>
        /// <param name="orders">Optional orderring</param>
        /// <returns>The entity or null</returns>
        public T FindFirst(DetachedCriteria criteria, params Order[] orders)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .GetExecutableCriteria(action.Value, criteria,
                                                                             CreateCriteria, orders);

                crit.SetFirstResult(0);
                crit.SetMaxResults(1);
                return((T)crit.UniqueResult());
            }
        }
        /// <summary>
        /// Loads all the entities that match the criteria, with paging
        /// and orderring by a multiply fields.
        /// </summary>
        /// <param name="firstResult">The first result to load</param>
        /// <param name="numberOfResults">Total number of results to load</param>
        /// <param name="criteria">the cirteria to look for</param>
        /// <returns>number of Results of entities that match the criteria</returns>
        /// <param name="selectionOrder">The fields the repository should order by</param>
        public ICollection <T> FindAll(int firstResult, int numberOfResults, Order[] selectionOrder,
                                       params ICriterion[] criteria)
        {
            using (DisposableAction <ISession> action = ActionToBePerformedOnSessionUsedForDbFetches)
            {
                ICriteria crit = RepositoryHelper <T> .CreateCriteriaFromArray(action.Value, criteria, selectionOrder);

                crit.SetFirstResult(firstResult)
                .SetMaxResults(numberOfResults);
                return(crit.List <T>());
            }
        }