NHUnit 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NHUnit --version 1.0.0
                    
NuGet\Install-Package NHUnit -Version 1.0.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="NHUnit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NHUnit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NHUnit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NHUnit --version 1.0.0
                    
#r "nuget: NHUnit, 1.0.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.
#:package NHUnit@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NHUnit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NHUnit&version=1.0.0
                    
Install as a Cake Tool

NHUnit

NHUnit is a simple but powerful Unit of Work and Repository pattern implementation for NHibernate which fixes proxy issues and simplifies child nodes loading. NHUnit provides sync and async versions for each method.

Eager loading

Using lambda expressions you can specify which child properties should be populated. The framework will determine the fastest approach to load the data: using join, future queries or by using batch fetching. Depending on the number of returned rows and the depth you might need to finetune your queries, but in most of the cases the framework takes the best decision.

var customer = await _dbContext.Customers.Get(customerId) //returns a wrapper to configure the query
               .Include(c => c.Addresses.Single().Country, //include Addresses and Country
                   c => c.PhoneNumbers.Single().PhoneNumberType) //include all PhoneNumbers with PhoneNumberType
               .Unproxy() //instructs the framework to strip all the proxy classes when the Value is returned
               .Deferred() //instructs the framework to delay execution
               .ValueAsync(token); //this is where the query gets executed

The expression c.Addresses.Single().Country will load all the nested child objects. Addresses is a colection and you need to use Addresses.Single() to include the nested children. The whole collection will be populated, not just the first item.

Unproxy

You can use IUnitOfWork.Unproxy, ISingleEntityWrapper.Unproxy or IEntityListWrapper.Unproxy

var customer = await _dbContext.Customers
                    .Get(customerId) //returns a wrapper to configure the query
                    .Unproxy() //instructs the framework to strip all the proxy classes when the Value is returned
                    .ValueAsync(token); //this is where the query gets executed

Transactions

IUnitOfWork exposes:

  • BeginTransaction
  • CommitTransactionAsync - pushes changes and commits transaction
  • RollbackTransactionAsync
  • SaveChangesAsync - pushes changes to DB but doesn't commit transaction (if any)
  • ClearCache - evict all loaded instances and cancel all pending saves, updates and deletions

Procedures/Queries

In some rare cases you need to execute your own queries and NHUnit provides this functionality:

  • ExecuteListAsync
  • ExecuteScalarAsync
  • ExecuteNonQueryAsync
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.2.0 646 2/4/2021
1.1.1 581 1/29/2021
1.1.0 552 1/15/2021
1.0.0 610 1/12/2021

Release of NHibernate Unit of Work