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);
#endregion }
Here is a sample implementation:
public class CustomerFreeTextPredicate : IPredicate<Customer> { #region Fields
private readonly string _searchTerm;
#endregion
#region Constructors and Destructors
public CustomerFreeTextPredicate(string searchTerm) { _searchTerm = searchTerm; // DisplayName = string.Format(Resources.CustomerFreeTextPredicate, _searchTerm); }
#endregion
#region IPredicate<Customer> Members
public string DisplayName { get; set; }
public Expression<Func<Customer, bool>> ApplyFilter(Expression<Func<Customer, bool>> filter) { return filter.And( x => (x.CustomerName.Contains(_searchTerm) || x.CustomerNumber.Contains(_searchTerm)) && x.LegalEntityRefs.Any( ler => ler.LegalEntityID.Equals(VisUser.LegalEntityId) && (ler.IsDeleted.HasValue && ler.IsDeleted.Value == false) && ler.IsActive.Equals(true))); }
#endregion }
That all works, due to you fantastic implementaion of IRepository<T> !
|