Quantcast
Viewing all articles
Browse latest Browse all 13

Mapping custom lists with Fluent NHibernate

NHibernate supports mapping to a few collection types by default, like IList of ISet, but they must be interfaces. To support other types of collections, including concrete classes, you should implement IUserCollectionType inteface. Being lazy as I am, however, I found a way to map custom collections as components using Fluent NHibernate. Here’s how it looks like:

Component(x => x.ChildUsers,
					  m => m.HasMany<User>(Reveal.Member<BindingList<User>>("innerList")).KeyColumn("parent_user_id").Access.Field());

The custom collection in this case is BindingList(T), a generic implementation of IBindingList interface for my own use. The trick is that it has to have a innerList field of any supported NHibernate collection type.

There are other variations of such mappings on the net, but other didn’t work for me with SQLite, throwing exceptions about generated DDL for tables.


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 13

Trending Articles