NHibernate Dialect for Cloud Spanner is now Generally Available
Knut Olav Løite
The Cloud Spanner NHibernate Dialect is now Generally Available
Do you have an application that you developed with NHibernate and now you want to migrate to a cloud database? Google Cloud Spanner now supports the NHibernate Object Relational Mapper. You can reuse existing NHibernate code with the Cloud Spanner NHibernate dialect, or write new features while leveraging existing knowledge.
The Cloud Spanner NHibernate dialect implements all the classes and interfaces that are needed to use Cloud Spanner with NHibernate. Add the Spanner NHibernate nuget package to your project and connect to Cloud Spanner as follows:
Install the Spanner NHibernate dialect:
dotnet add package Google.Cloud.Spanner.NHibernate --version 1.0.0
Connect to Cloud Spanner with NHibernate:
You can also use a custom connection provider or a user supplied connection with Spanner NHibernate. See this example for more information.
The Cloud Spanner NHibernate dialect supports standard NHibernate features, like querying data using both the NHibernate Criteria API and Linq, managing associations and executing transactions. The dialect also supports specific Spanner features such as interleaved tables, mutations and stale reads.
Query with Linq
NHibernate 3.0 introduced the Linq to NHibernate provider. The Spanner NHibernate dialect implements translations for the most commonly used functions and operators so these can be used with LInq.
Using interleaved tables for parent-child relationships in your schema can improve performance. Interleaving a child table with a parent means that the child records will be stored physically together with the parent. These relationships can be modeled and used as any other association in NHibernate.
This directory contains the complete mapping of all the entities that are used in the sample above.
NHibernate will use Data Manipulation Language (DML) by default. You can instruct NHibernate to use mutations for all transactions that are executed using a specific NHibernate session, or for a single transaction.
The GitHub repository contains a directory with multiple samples for common use cases for working with NHibernate and/or Cloud Spanner.
Cloud Spanner features that are not supported in NHibernate are listed here.
We'd love to hear from you, especially if you're a .NET developer considering Cloud Spanner or an existing Cloud Spanner customer who is considering using NHibernate for new projects. The project is open-source, and you can comment, report bugs, and open pull requests on Github.