I like the idea, with a minor twist: instead of implementing the interface in each query API and casting explicitly, you could expose an Options() method that returns IQueryOptions from any API. In fact, you can implement this as an extension method to all query interfaces, and it wouldn't even be a breaking change.
On Thu, Nov 20, 2014 at 2:44 PM, Ricardo Peres <rjpe...@gmail.com> wrote: > Hi, > > I submitted a pull request for https://nhibernate.jira.com/browse/NH-2140. > The idea is to have all query APIs (LINQ, HQL, SQL, Criteria and QueryOver) > support a base interface, which I called IQueryOptions. > This interface has common methods for paging, limiting the number of > records, setting read only, setting lock mode, setting a result > transformer, queuing to future queries, and performing the actual query. It > is defined as: > > public interface IQueryOptions > { > IList List(); > > void List(IList list); > > IList<T> List<T>(); > > object UniqueResult(); > > T UniqueResult<T>(); > > IQueryOptions SetFirstResult(int firstResult); > > IQueryOptions SetFetchSize(int fetchSize); > > IQueryOptions SetReadOnly(bool readOnly); > > IQueryOptions SetCacheable(bool cacheable); > > IQueryOptions SetCacheRegion(string cacheRegion); > > IQueryOptions SetTimeout(int timeout); > > IQueryOptions SetMaxResults(int maxResults); > > IQueryOptions SetLockMode(string alias, LockMode lockMode); > > IQueryOptions SetResultTransformer(IResultTransformer > resultTransformer); > > IFutureValue<T> FutureValue<T>(); > > IEnumerable<T> Future<T>(); > } > > > Because it was required for LINQ, I also included > https://nhibernate.jira.com/browse/NH-3299, > https://nhibernate.jira.com/browse/NH-3470 and > https://nhibernate.jira.com/browse/NH-2285. > It allows doing these without caring what API is actually being used: > > IQueryOptions query = //... > > query = query.SetReadOnly(true); > query = query.SetFirstResult(1); > query = query.SetMaxResults(1); > query = query.SetFetchSize(100); > query = query.SetLockMode(alias, LockMode.Upgrade); > query = query.SetResultTransformer(transformer); > var result = query.List<Simple>(); > > > What do you think? Let me hear your comments. > > > RP > > -- > > --- > You received this message because you are subscribed to the Google Groups > "nhibernate-development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to nhibernate-development+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- --- You received this message because you are subscribed to the Google Groups "nhibernate-development" group. To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-development+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.