NHibernate.QueryBuilder 1.1.0

dotnet add package NHibernate.QueryBuilder --version 1.1.0
NuGet\Install-Package NHibernate.QueryBuilder -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NHibernate.QueryBuilder" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NHibernate.QueryBuilder --version 1.1.0
#r "nuget: NHibernate.QueryBuilder, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NHibernate.QueryBuilder as a Cake Addin
#addin nuget:?package=NHibernate.QueryBuilder&version=1.1.0

// Install NHibernate.QueryBuilder as a Cake Tool
#tool nuget:?package=NHibernate.QueryBuilder&version=1.1.0

How to use it?

Simple example illustrating preferred conventions:

  1. Implementing a query class
  internal enum UserAlias  {
      Role,
      Right,
      Group
  }

  internal class UsersQuery : Query<UserPersistent, UserAlias>
  {
      private readonly RolePersistent _role = null;
      private readonly RightPersistent _right = null;
      private readonly GroupPersistent _group = null;

      protected override IDictionary<UserAlias, string> Aliases => 
          new Dictionary<UserAlias, string>
          {
              [UserAlias.Role] = nameof(_role),
              [UserAlias.Right] = nameof(_right),
              [UserAlias.Group] = nameof(_group)
          };
      

      internal UsersQuery WithRolesAndRights()
      {
          Query = Query
              .Left.JoinAlias(usr => usr.Roles, () => _role)
              .Left.JoinAlias(() => _role.Rights, () => _right);
          return this;
      }

      internal UsersQuery WithGroups()
      {
          Query = Query.Left.JoinAlias(usr => usr.Groups, () => _group);
          return this;
      }
  }
  1. Creating QueryBuilder for above:
  var builder = new QueryBuilder<UserPersistent, UserAlias>(session);
  1. Performing a query (let's say it's a very uncommon case, in which we want to find users who have role similar to 'Admin', are in a specific group type and are from within several countries - just for a demonstration purpose)
  public IEnumerable<User> FindUsersByWeirdCriteria(GroupType type, string[] countries)
  {
      IEnumerable<UserPersistent> users = builder.NewQuery()
          .WithRolesAndRights()
          .WithGroups()
          .Restrict.Like<RolePersistent>(UserAlias.Role, role => role.Name, 'Admin')
          .Restrict.In(usr => usr.Country, countries)
          .Restrict.Eq<GroupPersistent>(UserAlias.Group, grp => grp.Type, groupType)
          .Build()
          .List();

      //some mapping logic
      return users.Select(usr => mapper.MapToEntity(usr));
  }

One thing to notice - restrictions made on aliased classes require usage of <T> typed methods in contrast to methods working directly on type of query (TPersistent) where only property selector and value is required (see Restrict.In method call above). Alias resolution by key, and not only by type, is required to distinguish multiple join operations to the same table and add restrictions to the desired operation.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 752 3/12/2019
1.0.0 813 10/3/2018

Refactored aliases dictionary internals