Queries
ALL THE EXAMPLES FROM THIS POST ARE EXTRACTED FROM THE FWKLIGHT DEMO. TO FIND OUT HOW TO GET STARTED WITH THE DEMO, READ THIS POST.
The Query is the interface through which you will load lists of aggregates.
Whenever you need to load a list of aggregates from the database, you should think of a query.
Whenever you need to load one aggregate based on certain filters / rules, you should not use a query. By convention, the query is for loading lists of aggregates. To load one aggregate, you should always use a LoadTask (which will automatically use a repository).
Queries are services which live somewhere between the database and the domain. Together with the repositories, they form a bridge between your application and the database. Using them for more than just loading lists of aggregates can lead to instable or low quality code, because you are taking business logic away from the domain.
Here is an example of a Query which loads all entities with IDs in the given list:
public class SomeEntityListQuery: MultiCriteriaQuery<SomeEntity> { private IList<int> _ids; public IList<SomeEntity> Execute(ISession session, IList<int> ids) { _ids = ids; return Load(session); } protected override void ApplyMainFilters(IListMultiCriteriaFetcher<SomeEntity> criteria) { criteria.Where(p => p.Id).In(_ids); } protected override void FilterOnlyActive(IListMultiCriteriaFetcher<SomeEntity> criteria){} protected override void Sort(IListMultiCriteriaFetcher<SomeEntity> criteria){} }
About this entry
You’re currently reading “Queries,” an entry on The FwkLight blog
- Published:
- April 26, 2010 / 10:24 am
- Category:
- Uncategorized
- Tags:
No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]