TDD
Test driven developement
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....
This is the third post in a series of articles where I want to analyze and describe the new upcoming mapping interface providing a fluent interface to NHibernate for the mapping of a domain model to the underlying database. The other posts are A fluent interface to NHibernate A fluent interface to NHibernate - Part 2 - Value Objects A fluent interface to NHibernate - Part 4 - Configuration You can get the source code of the solution accompanying this post here. In the time...
Introduction When developing an application using DDD one starts by trying to define a model of the domain for/in which the application should be used. At the same time you try to establish the so called ubiquitous language. At some point you might need to store and or retrieve data into or from a data source. Very often this data source is a relational database. But it's not necessarily always the case. It could as well be a web service or a XML document. That leads me to the notion that "the database is just an implementation detail of...
Introduction The Castle ActiveRecord project is an implementation of the ActiveRecord pattern for .NET. The ActiveRecord pattern consists on instance properties representing a record in the database, instance methods acting on that specific record and static methods acting on all records. Castle ActiveRecord is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly. You can find the home page of the Castle project here. How will we use it? My intent is not to implement the ActiveRecord pattern...
Introduction In the previous two posts which you can find here and here I introduced the Unit of Work pattern and developed a working version based on NHibernate. One weak point of the shown implementation is that it is strictly non thread safe. In NHibernate the session object takes the role of the Unit of Work container. The session object is not thread safe! That is a session instance may not be accessed from different threads. If your application is running on multiple threads (typically an application running on the server) then you have to open a new session...
In the first part of this series I have started to implement the Unit of Work pattern. In this post I'll finish this implementation (for non-thread safe version) and in a third post I'll discuss how to make this implementation thread safe. Design and Implementation The Unit Of Work Factory The creation of a unit of work instance is a complex process and as such is a good candidate for a factory. Since a UoW (Unit of Work) is basically a wrapper around a NHibernate session object I'll need to open such a session whenever...
Introduction Martin Fowler writes: "When you're pulling data in and out of a database, it's important to keep track of what you've changed; otherwise, that data won't be written back into the database. Similarly you have to insert new objects you create and remove any objects you delete." and "A Unit of Work keeps track of everything you do during a business transaction that can affect the database. When you're done, it figures out everything that needs to be done to alter the database as a result of your work." In NHibernate we have...
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...
Full TDD Archive