Introduction to static reflection

This post could’ve also been called “Fluent NHibernate secrets exposed!” but it sounded a bit sensationalist.

You may have heard people mention static reflection recently, quite possibly because it’s used extensively in Fluent NHibernate, Rhino Mocks, and I believe Jimmy Bogard’s new AutoMapper also uses it; pretty much any of the new “fluent” interfaces use some kind of static reflection.

So what actually is static reflection? Well, it’s a statically compiled way of utilising the Reflection API.

Read more »

Fluent NHibernate: Auto mapping and base-classes

Carrying on with the Fluent NHibernate Auto Mapping theme, I’ll now demonstrate how to map inheritance hierarchies.

There are two main things that you’d want to do with inherited classes, either ignore the base class all together, or map them using an inheritance strategy. I’m going to start with the former, then move on to the latter.

Read more »

Fluent NHibernate: Auto Mapping Components

Notice: The content in this post may be out of date, please refer to the Auto Mapping page in the Fluent NHibernate Wiki for the latest version.

I’ve just committed a change that should allow automatic mapping of simple components; by simple, I mean components that just map properties, nothing fancy. I’ll be looking to expand this functionality in the future, but for the time being any kind of relationships aren’t supported within components. With that in mind, I’ll walk through how to automap your components.

Read more »

Fluent NHibernate: Mapping private and protected properties

Notice: The content in this post may be out of date, please refer to the Fluent Mapping page in the Fluent NHibernate Wiki for the latest version.

There’s been a point of contention for some users of Fluent NHibernate since the beginning, and that’s the lack of a method of mapping private and protected properties on their domain entities.

The issue stems from our use of lambda expressions for static reflection of your entities, one of the appealing properties of Fluent NHibernate; by utilising expressions we’re able to protect your mappings from refactoring side-effects. However, lambda expressions can only reference properties that are public on an object, so that makes it difficult to use against protected or private properties.

Read more »

Fluent NHibernate: Auto Mapping Type Conventions

Notice: The content in this post may be out of date, please refer to the Auto Mapping page in the Fluent NHibernate Wiki for the latest version.

I’ve already covered how to auto map a basic domain, as well as how to customise some of the conventions that the auto mapper uses. There are some more in-depth customisations you can do to the conventions that I’ll cover now.

Read more »