# Persistence with FluentNHibernate

Tags: , , , | Categories: .NET Posted by oleksii on 1/10/2011 12:23 AM | Comments (0)

Domain Driven Design defines several terms within its scope, such as an entity and a value object (value object in .NET is not the same as in DDD). An entity is an object that can be found by its identity and a value object, in contrast, does not require any identity. Database persistence for such objects is different. Entities of one particular type are persisted to a database within one dedicated table. Value objects do not have this privilege and are stored within the master entity's table. ORM needs to be pointed which type is an entity and which is a value object.

Suppose using DefaultAutoMapping class of FluentNhibernate. Entities are then grabbed by a ShouldMap method, such as:

public override bool ShouldMap(Type type)
{
bool result = type.Namespace.StartsWith("Core.Model") &&
!type.Namespace.StartsWith("Core.Model.ValueObjects");

return result;
}


Value objects are called components (FluentNHibernate components). They are picked up by IsComponent method.

public override bool IsComponent(Type type)
{
return type.Namespace.StartsWith("CHB.Core.Model.ValueObjects");
}


Such notation may not be apparent from the first glimpse and may be a source of a small investigation.

If you enjoyed this post, make sure you subscribe to my RSS feed!