Print Page | Close Window


Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
Printed Date: 10-Aug-2020 at 7:39pm

Topic: IPager<T>
Posted By: cypher
Subject: IPager<T>
Date Posted: 20-Nov-2013 at 7:31am
We have started to Implement the IPagerRepository<T> with Cocktail.

The Implementation is straight forward with the help of you'r Documentation.

But we are really not happy, that we have to Query the complete last Page, in order to have the TotalAmount initalized in The 

We have traced the Querys on SQL Profiler, and found out, that we have to fire three Querys 

2. LastPage
3. FirstPage

To initialize the IPager<T> to show the Pager.TotalDataSourceItemCount.

This is really sad, because we would like to query the database for the cound, if the first query starts.

Is there a Way for you to implement the IPager<T> from Cocktail, to have it initialize (Count) if the Pager.TotalDataSourceItemCount == -1 without loading the last page?

We really want to avoid, loading the last page, just to initialize the pager (get the TotalSourceItem)

Posted By: mgood
Date Posted: 20-Nov-2013 at 12:58pm
Unfortunately, there is not. EF doesn't provide an inline count. You either have to run a count query or fetch the last page to know how many total records there are. That's just how it is. I recommend not to use the Total properties from IPager<> and instead just make a call to CountAsync() to get the total count and use that to calculate the number of pages etc. 

Posted By: cypher
Date Posted: 21-Nov-2013 at 6:38am
Thank you for you answer.

We have stripped out the generation of Predicates (Filters on an Entity) and pass it now into a SearchService, that has a Count And IPager Method.

   /// <summary>
    ///     Predicate to filter the entities.
    /// </summary>
    /// <typeparam name="T">the Model/Projection to apply the filter on</typeparam>
    public interface IPredicate<T> : where T : IEntity
        #region Public Methods

        /// <summary>
        ///     Applies the filter.
        /// </summary>
        /// <returns></returns>
        Expression<Func<T, bool>> ApplyFilter(Expression<Func<T, bool>> filters);


Here is a sample implementation:

 public class CustomerFreeTextPredicate : IPredicate<Customer>
        #region Fields

        private readonly string _searchTerm;


        #region Constructors and Destructors

        public CustomerFreeTextPredicate(string searchTerm)
            _searchTerm = searchTerm;
          //  DisplayName = string.Format(Resources.CustomerFreeTextPredicate, _searchTerm);


        #region IPredicate<Customer> Members

        public string DisplayName { get; set; }

        public Expression<Func<Customer, bool>> ApplyFilter(Expression<Func<Customer, bool>> filter)
                    x =>
                    (x.CustomerName.Contains(_searchTerm) || x.CustomerNumber.Contains(_searchTerm)) &&
                        ler =>
                        ler.LegalEntityID.Equals(VisUser.LegalEntityId) && (ler.IsDeleted.HasValue && ler.IsDeleted.Value == false) &&


That all works, due to you fantastic implementaion of IRepository<T> !

Print Page | Close Window