Recently Oren (Ayende) had a serious of posts on NHibernate mappings and the various options you can configure using Xml mappings. This series of posts takes those examples and shows how you can use FluentNHibernate to configure the same mappings.

This is a companion post for Oren’s post on the <any> mapping in NHibernate, here. I recommend reading his post before venturing forward.

In Fluent NHibernate you can use the ReferencesAny mapping method to output a <any> mapping:

ReferencesAny(mapping => mapping.Payment)

    .EntityTypeColumn("PaymentType")

    .EntityIdentifierColumn("PaymentId")

    .AddMetaValue<CreditCardPayment>("Credit")

    .AddMetaValue<CheckPayment>("Check")

    .IdentityType(identity => typeof(int));

Note: This mapping method at this time is generating the <any> mapping incorrectly. The mapping that is being generated contains <any> before the <Id> element causing NHibernate to complain. I've submitted a patch to fix this behavior, which you can get from here: http://code.google.com/p/fluent-nhibernate/issues/detail?id=228

Note2: ReferencesAny is available in the latest trunk as support for it was added fairly recently. So if you can't seem to find it in the fluent-nhibernate.dll build you are using, get latest from trunk and build it.

The ReferencesAny prety much matches the <any> element. You specify the meta values using the AddMetaValue method, the type column via EntityTypeColumn and the identity column using the EntityIdentifierColumn method.

Posted on Friday, May 15, 2009 6:00 AM | Filed Under [ NHibernate FluentNHibernate ]


Comments

Gravatar
# re: FluentNHibernate Mappings: Any
Posted by UGGs outlet
on 10/11/2011 4:37 AM
nice postSS
Post Comment
Title *
Name *
Email
Url
Comment *  
Please add 3 and 3 and type the answer here: