NHibernate.FlowQuery v2.3.0 Released

Finally got the time to manage a new version of NHibernate.FlowQuery (FlowQuery) that utilizes NHibernate 4.0 that was released not so long ago (although FOREVER for those of you who might have been waiting for me to release this, I know, sorry!). Version 2.3.0 of FlowQuery is most of all an upgrade to NHibernate 4.0 but I’ve also managed to squeeze in a few new features (new projection possibilities and a new extension point), see the release notes below for more info.

Version 2.3.0 of FlowQuery can be downloaded here. FlowQuery is, as the last two releases, available on NuGet.

Install using NuGet:

PM> Install-Package NHibernate.FlowQuery

 

Release Notes:

Improvements

  • Logic for resolving method call projections should be split up to make code more maintainable and extensible

New Features

  • Add possibility to project Trim (on string properties/values)
  • Add possibility to project TrimEnd (on string properties/values)
  • Add possibility to project TrimStart (on string properties/values)
  • Add possibility to project Math.Round
  • Add possibility to add custom logic to resolve method call projections
  • Add possibility to override default logic to resolve method call projections

Tasks

  • Remove unnecessary hyphens in comments (cache-able, sub-query, etc.)
  • Upgrade to NHibernate 4.0

You can read more on the new extension point here. The new projection features are briefly described here (Math.Round) and here (Trim, TrimEnd, TrimStart).

Enjoy! (:

NHibernate.FlowQuery v2.2.0 Released

I’m happy to announce version 2.2.0 of NHibernate.FlowQuery (FlowQuery) which mostly improves on the in-code documentation and fixes a few important bugs in the NuGet package. The new version also contains a bunch of code changes, although none of them should affect you too much (hopefully not at all), unless you’re extending the library (see the release notes below). A few new features, however small they might be, are also available.

Version 2.2.0 of FlowQuery can be downloaded here. FlowQuery is, as the last two releases, available on NuGet.

Install using NuGet:

PM> Install-Package NHibernate.FlowQuery

 

Release Notes:

Bug Fixes

  • NuGet package should include license file
  • NuGet package should include release notes file

Improvements

  • Property names for orders set using OrderBy/OrderByDescending(..) should not be case sensitive
  • Add XML DOC comments to provide developers with better in-code documentation (intellisense, etc.)
  • Modify detached queries to not be able to project multiple properties (as sub-queries can’t do that anyway)
  • Modify FetchBuilder to take an instance of IFlowQuery instead of FlowQueryBase
  • Modify JoinBuilder to take an instance of IFlowQuery instead of FlowQueryBase
  • Modify LockBuilder to take an instance of IFlowQuery instead of FlowQueryBase
  • Introduce an interface for PartialSelection which should be returned by “query.PartialSelect”
  • NuGet package should include the new help file (generated using SandCastle)

New Features

  • Add possibility to Suppress errors when adding orders set using OrderBy/OrderByDescending(..)
  • Add possibility to specify custom criteria builder instead of using static helper (CriteriaHelper)
  • Add possibility to create truly detached queries (e.g. without ISession or IStatelessSession references)

Tasks

  • Introduce the use of StyleCop to enforce basic coding style rules.
  • Introduce the use of SandCastle to generate documentation help files
  • Rename class DelayedFlowQueryImplementor to DelayedFlowQuery
  • Rename class DetachedFlowQueryImplementor to DetachedFlowQuery
  • Rename class DetachedImmutableFlowQueryImplementor to DetachedImmutableFlowQuery
  • Rename class FlowQueryImplementor to FlowQueryBase
  • Rename class ImmediateFlowQueryImplementor to ImmediateFlowQuery
  • Rename class MorphableFlowQueryImplementor to MorphableFlowQueryBase
  • Rename class QueryableFlowQueryImplementor to QueryableFlowQueryBase
  • Rename namespace NHibernate.FlowQuery.Core.Implementors to NHibernate.FlowQuery.Core.Implementations
  • Move ExampleWrapper to NHibernate.FlowQuery.Core.Implementations namespace
  • Move JoinBuilder to NHibernate.FlowQuery.Core.Implementations namespace
  • Move LockBuilder to NHiberate.FlowQuery.Core.Implementations namespace
  • Move FetchBuilder to NHiberate.FlowQuery.Core.Implementations namespace
  • Move PartialSelection to NHiberate.FlowQuery.Core.Implementations namespace
  • Move PartialSelectionBuiler to NHiberate.FlowQuery.Core.Implementations namespace
  • Move SelectionBuilder to NHiberate.FlowQuery.Core.Implementations namespace
  • Move SelectSetup to NHiberate.FlowQuery.Core.Implementations namespace
  • Move SelectSetupPart to NHiberate.FlowQuery.Core.Implementations namespace
  • Move IJoinBuilder to NHibernate.FlowQuery.Core namespace
  • Move ILockBuilder to NHibernate.FlowQuery.Core namespace
  • Move IFetchBuilder to NHibernate.FlowQuery.Core namespace
  • Move ISelectSetup to NHibernate.FlowQuery.Core namespace
  • Move ISelectSetupPart to NHibernate.FlowQuery.Core namespace
  • Move Join to NHibernate.FlowQuery.Core.Structures namespace
  • Move Lock to NHibernate.FlowQuery.Core.Structures namespace
  • Move Fetch to NHibernate.FlowQuery.Core.Structures namespace
  • Move OrderByStatement to NHibernate.FlowQuery.Core.Structures namespace
  • Move Pair to NHibernate.FlowQuery.Core.Structures namespace
  • Clean out all “MetaDataFactory” references (as they are not used, nor planned to be used in the near-future)

The biggest change or this release is the in-code documentation which should provide you all with, just a tiny bit, better intellisense when working with FlowQuery. It also made it possible to generate a proper help file (.chm) using Sandcastle Help File Builder. The help file can be downloaded at SourceForge and is also part of the NuGet package (it should be found in the package folder).

I’ve also altered the documentation page to maintain the documentation of old versions by adding sub-pages for each version being released. Why don’t you take a look at the documentation page and let me know what you think?

Enjoy! (:

NHibernate.FlowQuery v2.1.1 Released

Sad to say that I, in my haste to release version 2.1 of NHibernate.FlowQuery (FlowQuery), mistakenly copied the wrong license text into the “License.txt” file.

Instead of the intended license text for Lesser General Public License (LGPL) I had copied the license text for General Public License (GPL).

I’ve corrected this error in version 2.1.1 of FlowQuery which is released both on SourceForge.net and on NuGet. I’ve also corrected the license text on this WordPress Site and in the old packages released on SourceForge.net.

Unfortunately, it seems to be impossible to update/delete a package on NuGet and hence, I cannot fix the problem in the version 2.1.0 NuGet package, which I’ve unlisted instead.

So, please enjoy version 2.1.1 of FlowQuery! (:

NHibernate.FlowQuery v2.1 Released

I’ve just released version 2.1 of NHibernate.FlowQuery (FlowQuery) which I’ve been busy working on for the last couple of weeks. The new version contains a couple of bug fixes but mostly new features and improvements.

Version 2.1 of FlowQuery can be downloaded here. FlowQuery is now also available on NuGet.

Install using NuGet:

PM> Install-Package NHibernate.FlowQuery

 

Release Notes:

Bug Fixes

  • OrderBy(..) cause query to have same sql projection twice instead of using alias, which cause a crash when also using Distinct()
  • OrderBy(..) cause a crash when used with more complex projections (ternary operations/expressions etc.)

Improvements

  • Should sign assembly with a strong name key
  • Should mark assembly with AllowPartiallyTrustedCallersAttribute
  • Should mark assembly with CLSCompliantAttribute
  • Aggregate.Average should return Double instead of Decimal to avoid multiple type casts in sql
  • Is.In(TEnumerable enumerable) where TEnumerable : IEnumerable should just be Is.In(IEnumerabe enumerable)

New Features

  • Should support ICriteria.SetFetchMode features (e.g. query.Fetch(x => x.Association).WithJoin())
  • Should support ICriteria.SetCacheable/SetCacheRegion/SetCacheMode features (e.g. query.Cacheable([string], [CacheMode]))
  • Should support ICriteria.SetTimeout features (e.g. query.Timeout(int) and query.TimeoutAfter(int).Seconds())
  • Should support ICriteria.SetLockMode features (e.g. query.Lock([alias]).[LockMode]())
  • Should support ICriteria.SetReadOnly features (e.g. query.ReadOnly([bool]))
  • Should support ICriteria.SetComment features (e.g. query.Comment(string))
  • Should support ICriteria.SetFetchSize features (e.g. query.FetchSize(int))
  • Should support Restrictions.IsEmpty/IsNotEmpty and Subqueries.Exists/NotExists features (e.g. Is.Empty(..) and Is.Not.Empty(..))
  • Should support Projections.SubQuery features (e.g. Aggregate.Subquery(..))
  • Should support projections with simple type casting (e.g. (int)x.MyProperty)
  • Should infer GroupBy columns from other projections (aggregations, explicit GroupBy)
  • Should be able to GroupBy without projecting value (e.g. query.GroupBy(..))
  • Should be able to copy/clone a FlowQuery reference (e.g. query.Copy())
  • Should be able to clear all restrictions (e.g. query.ClearRestrictions())
  • Should be able to clear time out (e.g. query.ClearTimeout())
  • Should be able to clear group bys (e.g. query.ClearGroupBys())
  • Should be able to clear fetches (e.g. query.ClearFetches())
  • Should be able to clear locks (e.g. query.ClearLocks())
  • Is.In(..) should have overload accepting a DetachedCriteria
  • SessionExtensions should provide methods for getting Detached/Delayed (+ explicit Immediate) FlowQuery alterations directly

Tasks

  • Add license file (e.g. “License.txt”)
  • Add release notes file (e.g. “Release Notes.txt”)
  • Add read me file (e.g. “Read Me.txt”)
  • Add NuGet support

I’ve also updated the unit test suite (~150 new tests) and the documentation to cover the new features and improvements.

Enjoy! (:

NHibernate.FlowQuery v2.0 Released

The last couple weeks I’ve been working fervently with a new major version of NHibernate.FlowQuery (FlowQuery) with a better (read as: more flexible and maintainable) syntax which supports MultiCriteria (Futures), interchangeability (morphing) and re-usability.

Version 2.0 of FlowQuery can be downloaded here. The new version is built against NHibernate 3.3.3.

I’m very happy with what I have to present, but I don’t think my regular kind of short release notice would do the job this time. Therefore I have also put some time aside to document the most of the project properly (from a usage point of view).

The documentation is divided into the following topics:

I’ve also added a contact page where you can report bugs/issues or simply request a feature. This will have to do until I find a nice place to set up a proper issue tracking system.

I hope you will enjoy the new version as much as I have enjoyed developing and documenting it! (:

/Niklas Källander

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.9 Released

Just uploaded a new version of NHibernate.FlowQuery ( FlowQuery ). Version 0.9 of FlowQuery can be downloaded here. The new version is built against both NHibernate 2.1.2 and NHibernate 3.1.0. Both builds contains several minor bug fixes and small improvements to the joining API. The build against NHibernate 3.1.0 however also contains overloads for all Join methods that takes a parameter specifying extra on-clause criteria.

Example:

UserGroupLink link = null;

var activeGroupIds = Query<User>()
    .Join(u => u.Groups, () => link, u => link.IsActive)
    .Select(u => link.Group.Id);

The above Join-call will translate into something like this ( in the ICriteria API ):

criteria.CreateAlias("Groups", "link", JoinType.InnerJoin, Restrictions.Eq("link.IsActive", true));

That’s about it for now.

Enjoy! (:

/Niklas Källander

NHibernate.FlowQuery v0.8 Released

Today I finally got the time to release a new version of NHibernate.FlowQuery ( FlowQuery ). Version 0.8 of FlowQuery can be downloaded here. The new version contains one new feature ( OrderBy<TProjection>, which lets you order your result set by one ( or more ) of the projections ), a few bug fixes ( Is.Not.* in sub-queries now actually negates the expression which it, somehow, didn’t in the previous version ) and a minor change in the API ( an IRevealer now exposes its’ IRevealConvention ).

The new feature can be used like this:

var users = session.FlowQuery<User>()
    .OrderBy<UserDto>(x => x.Name)
    .Select(x => new UserDto()
    {
        Name = x.Firstname + " " + x.Lastname
    });

This is actually the same as doing:

var users = session.FlowQuery<User>()
    .OrderBy(x => x.Firstname + " " + x.Lastname)
    .Select(x => new UserDto()
    {
        Name = x.Firstname + " " + x.Lastname
    });

But it’s a bit more convenient, don’t you think?

The new feature also provides overloads to support strings:

var users = session.FlowQuery<User>()
    .OrderBy<UserDto>("Name")
    .Select(x => new UserDto()
    {
        Name = x.Firstname + " " + x.Lastname
    });

Every overload also has a matching OrderByDescending method and the new feature can also be combined with the old OrderBy-syntax with ease:

var users = session.FlowQuery<User>()
    .OrderBy(x => x.Age)
    .OrderBy<UserDto>(x => x.Name)
    .Select(x => new UserDto()
    {
        Age = x.Age,
        Name = x.Firstname + " " + x.Lastname
    });

The only possible downside is that it can only be used with projections made using ISelectSetup ( .For(x => x.Prop).Use(x => x.Prop) ) or a lambda expression ( member initializer ). It does not work using IProjections.

Enjoy! (:

/Niklas Källander

NHibernate.FlowQuery v0.7 Released

Today I released a minor update of NHibernate.FlowQuery (FlowQuery). Version 0.7 of FlowQuery can be downloaded here. The new version merely adds a small amount of functionality for joining hidden members and using select setup when projecting queries. It also fixes a bug when selecting hidden fields (which was somehow overlooked in the previous version).

The added functionality for joining hidden members is only a few overloads on the Join-methods to pipeline lambda expressions on to the Reveal-helper. This to reduce verbosity when joining.

An example, with the previous version:

Post post = null;
Comment comment = null;

session.FlowQuery<User>()
    .Join(u => u.Posts, () => post)
    .Join(Reveal.ByConvention(() => post.Comments), () => comment)
    .Select();

With the new version:

Post post = null;
Comment comment = null;

session.FlowQuery<User>()
    .Join(u => u.Posts, () => post)
    .Join(() => post.Comments, () => comment)
    .Select();

For the sake of convenience there is also overloads to provide your own IRevealConvention:

session.FlowQuery<User>()
    .Join(u => u.Posts, () => post)
    .Join(() => post.Comments, () => comment, new UnderscoreConvention())
    .Select();

In the previous version of FlowQuery you could not use strings in the Use-part of a select setup. In the new version this is fixed and you don’t have to create your own PropertyProjection to overcome this misfortune. In other words…

session.FlowQuery<User>()
    .SelectDistinct()
        .For(x => x.Firstname).Use("Firstname")
        .Select();

…is now possible!

Enjoy! (:

/Niklas Källander

Aggregation with NHibernate.FlowQuery

Aggregation is quite easy in NHibernate.FlowQuery (FlowQuery) but in can be a bit unclear how to do it. This post is supposed to make it a bit clearer by giving a couple of examples.

With FlowQuery all aggregation is done by using the Aggregate-helper, like:

session.FlowQuery<User>()
    .Select(x => new
    {
        Average = Aggregate.Average(x.Id),
        Max = Aggregate.Max(x.Id),
        Min = Aggregate.Min(x.Id)
    });

This will return a FlowQuerySelection<Anonymous> containing one item that holds the selected aggregations.

Quite easy, right?

To group by a certain property, you also have to select that certain property in a GroupBy-aggregation, like:

session.FlowQuery<User>()
    .Select(x => new
    {
        Average = Aggregate.Average(x.Id),
        Max = Aggregate.Max(x.Id),
        Min = Aggregate.Min(x.Id),
        GroupedBy = Aggregate.GroupBy(x.Firstname)
    });

Now the aggregation will be grouped by Firstname and the returned FlowQuerySelection<Anonymous> will no longer contain only one item but instead one item for each unique Firstname in the database table.

Enjoy! (:

/Niklas Källander