It’s already fairly well documented that F# doesn’t play too well with NHibernate and Fluent NHibernate, although you can make it play a littler nice with a bit of effort. However there are a few fundamental problems with this approach. The first is F# class’ are not really designed to be data containers because that’s what its record type is for. The second is that F# class’ do not put too much emphasis on virtual methods as in functional programming we tend to using pass functions as values as a way to achieve polymorphism rather than virtual methods. Third and finally FluentNHibernate works with C#’s expression trees, it would be nice use F#’s quotation system instead.
Record types are a fixed collection of names and fields a lot like the row in a database. Below shows a record type we’d like to be able to store in a database table. Here we show an invoice record type that we’d like to serialize in the database.
What we’d like to be able to write is a mapping class that describes how it should be serialized, like you can do in FluentNHibernate:
The idea of FunctionalNHibernate is to provide a layer to do just this. As you see we provide a neat way to describe the mappings. We achieve the record serialization by providing a custom tupilizer for F# record types. There’s also the start of a wrapper for the SessionFactory that will hopefully allow you to store and retrieve data in way more natural for F#.
The idea of this project is not to detract from FluentNHibernate, it’s a great project and works really nicely from C#. I want to provide something that will work equally well from F#. We’re a long way behind them and to be honest the project isn’t really usable yet. I have project in mind that I want to use it on, so hopefully I’ll be able to improve it as I go along.
The result is you can now write the following program to store, update and retrieve our invoice record type:
The project is hosted on bitbucket.org, where you can explore or download the code. Feel free to drop me a line if you want to help out.
Feedback:
Feedback was imported from my only blog engine, it's no longer possible to post feedback here.
Social comments and analytics for this post - uberVU - social comments
This post was mentioned on Twitter by robertpi: Introducing FunctionalNHibernate: http://bit.ly/6tSmtE
The Morning Brew - Chris Alcock » The Morning Brew #502 - http://blog.cwa.me.uk/2009/12/21/the-morning-brew-502/
The Morning Brew - Chris Alcock » The Morning Brew #502
F# Discoveries This Week 12/21/2009 - Rick Minerich's Development Wonderland
By far the most exciting news this week was the preview release of Microsoft Research Accelerator. 
F# Database Programming – FunctionalNHibernate? « Tales from a Trading Desk - http://mdavey.wordpress.com/2009/12/25/f-database-programming-functionalnhibernate/
F# Database Programming – FunctionalNHibernate? « Tales from a Trading Desk
Xanax. - Xanax.
Buy xanax without prescription in usa. Xanax. No prescription xanax.
re: Introducing FunctionalNHibernate - Jim Ray
Great article!
Nit-pick: the plural of "class" is "classes."
http://grammar.ccc.commnet.edu/grammar/plurals.htm