NHibernate.FlowQuery v1.2 Released

There hasn’t been too many updates here the last two years so I thought it would be about time I said “Hi, I’m alive!”.
I’ve just uploaded a new version of NHibernate.FlowQuery ( FlowQuery ). Version 1.2 of FlowQuery can be downloaded here. The new version is built against NHibernate 3.3.2.

This release adds overloads for the *Join-methods on ISubFlowQuery giving you the possibility to specify extra onClause-criteria there as well as you have been able to do on the regular IFlowQuery for quite some time now. I have also added a short hand to IFlowQuery called Any() with a few overloads for specifying conditions. The methods works pretty much the same as the Any() method in the Linq API.

Example of Any() using:

bool anyUserOnline = Query<User>()
    .Any(u => u.IsOnline);

How to solve the above with previous version:

bool anyUserOnline = Query<User>()
    .Where(u => u.IsOnline)
    .Take(1)
    .Count() > 0;

As you can see, this gives you a little less to write in these occasions. I hope it’ll come in handy.

Enjoy! (:

/Niklas Källander

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.

Examples:

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")))
    .Select();

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))
    .Select();

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();

Mapping.SetMapper(mapper);

var dtos = session.FlowQuery<User>()
    .Select()
    .ToMap<UserDto>();

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