-
Notifications
You must be signed in to change notification settings - Fork 19
Using IQueryT
geoffreysmith edited this page Jun 1, 2011
·
2 revisions
Inspiration: Udi Dahan IQuery vs Methods on the Repository
IQuery<T>
is meant to replace methods on the repository, and lives in the Tasks Layer. Queries can then be passed down to lower layers to help populate viewModels, reporting or for usage in other applications. The contracts live in the Domain Layer and the implementation lives in the Infrastructure Layer. The convention is one file per query.
// One file per Query
public class ProductsForSaleQuery : NHibernateQuery<Product>, IProductsForSaleQuery
{
public override IList<Product> ExecuteQuery()
{
return (from product in Session.Query<Product>()
where product.SellEndDate.Date > DateTime.Parse("5/30/2003")
select product).ToList();
}
}
public interface IProductsForSaleQuery : IQuery<Product>
{
}
public IList<Product> GetProductsForSale()
{
return this.productRepository.PerformQuery(this.productsForSaleQuery);
}