NHibernate.FlowQuery v0.6 Released

Today I released a new version of NHibernate.FlowQuery (FlowQuery). Version 0.6 of FlowQuery can be downloaded here. The new version contains a couple of new and improved features and fixes a few bugs.

New and improved features:

  • Possibility to build a fluent query which uses the Is-helper, which further gives you the ability to combine several Is-helper-calls with both Or– and And-statements.
  • “Advanced” auto-mapping functionality. You can now provide your own mapper which in turn could be based on AutoMapper or any other mapping tool.
  • Improved and extended subqueries support. It is now possible to refer to the main query in the subquery and it is also possible to perform a few more restrictions using subqueries.

The new version also have 100% code coverage by unit testing.

Other changes:

  • FlowQueryOptions is reduced to having only a single public method called Add which takes an Action<ICriteria>.
  • The auto-mapping functionality is no longer performed in the select-statements, it is moved to FlowQuerySelection<TSource> which is returned by the select-statements.
  • The Not-member of the Is-helper is no longer a method taking an IsExpression, it is merely a property which negates the following IsExpression.


Building a fluent query with the Is-helper:

var users = session.FlowQuery<User>()
    .Where((u, where) => u.Username == "Niklas"
                        && (where(u.Role, Is.Not.EqualTo(Role.Administrator))
                        || u.Lastname.Contains("K")))

where in this case is a WhereDelegate which takes an object and an IsExpression and returns a bool.

Referencing the main query from a subquery:

User user = null;

var subquery = SubQuery.For<User>()
    .SetRootAlias<User>(() => user)
    .Where(x => x.Id == user.Id)
    .Select(x => x.Id);

var users = session.FlowQuery<User>(() => user)
    .Where(u => u.Id, Is.In(subquery))

The above query’s usage of a subquery is pretty worthless but it demonstrates the possibility of referencing the main query (root) in the subquery.

The new auto-mapping syntax:

IMapper mapper = new AutoMapperMapper();


var dtos = session.FlowQuery<User>()

IMapper is an interface which requires you to implement one single method:

TReturn Map<TSource, TReturn>(TSource source) where TReturn : new();

By default FlowQuery uses an IMapper which simply maps properties which have the same name and the same type in both source and destination.

Enjoy! (:

/Niklas Källander