Query
Techniques how to query the database with NHibernate
The popularity of NHibernate is steadily increasing. At the same time people get used to LINQ. Now there exists a LINQ to NHibernate provider since quite some time. It's not a complete implementation of a LINQ provider but it is still quite useful. Most of the day to day problems we face when developing typical business application can be solved by using this provider. And if there is a query that cannot be executed against the provider we still have the option to falling back to the hibernate query language (HQL). In this post I'll give you...
[Updated, 2008-11-20 --> see end of post] One of the questions that is asked again and again in the NHibernate user mailing list is the question about whether NHibernate supports lazy-loading of properties. The answer is NO - at least for the time being. Why is this question reasonable? Well, often we have entities in our domain that contain fields with large amount of data. Some samples are a large binary object (BLOB, e.g. an image, a Word document, a PDF, etc.), a large text object (CLOB, or nvarchar(max) )...
I'll try to dive deep into the caching of NHibernate in this article. This post has been inspired by the talk given by Oren Eini (aka Ayende) at the Kaizen Conference in Austin TX. Caching is a topic that is IMHO only superficially described so far especially regarding the second level cache. Most of the time one finds a lot of information about how to configure a specific cache provider for usage but the real usage (who and when) is not really described. I hope to be able to provide some of the missing pieces with this post....
Introduction When accessing data from a data source we have several well documented possibilities. Martin Fowler e.g. describes several of them in his PoEAA book. Table data gateway Row data gateway Active record Data mapper When applying DDD (domain driven design) we often use the so called Repository Pattern to access the data needed by the domain model. What is a Repository Martin Fowler writes: "A Repository mediates between the domain and data mapping layers,...
Introduction Lately there have been many questions regarding how to best map a tree structure in NHibernate. In this post I'll try to show you various techniques how one can deal with a tree structure. The code for this sample you can get from here. Domain Model Let's define a very simple domain model for this sample. We have a single class called Equipment that has a parent of type Equipment and 0 to many children of type Equipment. The tree has a single root node. The root node is specific by the fact that it's...
In a previous article I showed how to setup a developer machine to start using NHibernate as an ORM tool during the development of an application. I advocated a domain driven design (DDD) approach and a test driven development (TDD) style. This is the second article in a series of introductory chapters.
Define the Domain
Lets start by defining a very simple domain. For the moment it consists of one entity called Product. The product has 3 properties Name, Category and Discontinued.
Add a folder Domain to the FirstSample project of your solution. Add a new class Product.cs to this folder. The...