Fluent DML for NHibernate
Small proof of concept to run DML operations against NHiberate using Linq and a fluent interface. It supports Update and Delete commands.
Currently NHibernate provides DML via executing HQL queries. This is well documented in the manual
This project works by taking a Lambda function (Func<T,bool>) and converting this expression into HQL. This is then executed against the Session as normal.
This is provided via extension functions against the session.
Example
To update all the Person object where their name is James to have the Age of 21
using HQL
int updatedEntities = session.CreateQuery( "update Person as x set x.Age = :p1 where x.FirstName = :p2" )
.SetParameter( "p1", 21)
.SetParameter( "p2", "James")
.ExecuteUpdate();
using FluentDml
int executeCommand = session.Update(x => x.FirstName == "James")
.Set(x => x.Age, 123)
.ExecuteCommand();