Introducing FunctionalNHibernate

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.

Record type 

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:

functional nhibernate mapping 

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:

fun nhibernate program 

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.

Bookmark
dotnetkicks+, digg+, reddit+, del.icio.us+, dzone+, facebook+

Print | posted @ Sunday, December 20, 2009 12:26 PM

Comments on this entry:

Gravatar # Social comments and analytics for this post
by uberVU - social comments at 12/20/2009 1:37 PM

This post was mentioned on Twitter by robertpi: Introducing FunctionalNHibernate: http://bit.ly/6tSmtE
Gravatar # The Morning Brew - Chris Alcock » The Morning Brew #502
by Pingback/TrackBack at 12/21/2009 9:40 AM

The Morning Brew - Chris Alcock » The Morning Brew #502
Gravatar # F# Discoveries This Week 12/21/2009
By far the most exciting news this week was the preview release of Microsoft Research Accelerator. 
Gravatar # F# Database Programming – FunctionalNHibernate? « Tales from a Trading Desk
by Pingback/TrackBack at 12/25/2009 6:30 PM

F# Database Programming – FunctionalNHibernate? « Tales from a Trading Desk
Gravatar # Xanax.
by Xanax. at 12/26/2009 11:09 AM

Buy xanax without prescription in usa. Xanax. No prescription xanax.
Gravatar # re: Introducing FunctionalNHibernate
by Jim Ray at 12/30/2009 5:47 PM

Great article!

Nit-pick: the plural of "class" is "classes."

http://grammar.ccc.commnet.edu/grammar/plurals.htm
Gravatar # Best database engine or access for F#? – Chris Roland
by Pingback/TrackBack at 3/7/2010 4:46 AM

Best database engine or access for F#? – Chris Roland

Your comment:

(Note: all comments are moderated so it may take sometime to appear)

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 4 and 5 and type the answer here:
 

 Subscribe in a reader

Links

CVMy CV
stackoverflowMy Stack Overflow CV
Twitter Follow me on Twitter
FaceBook View my Facebook
LinkedIn View my LinkedIn Profile
Viadeo Viadeo Profile (Français)

Conferences/Workshops

Robert Pickering:Robert Pickering's Beginning F# Workshop,  Robert Pickering's Beginning F# Workshop
2 DAY COURSE. Featuring Robert Pickering
London, Monday, May 10th
Progressive .NET Tutorials, Progressive .NET Tutorials
CONFERENCE (3 DAYS)
London, Wednesday, May 12th BOOK NOW!

Badges


Progressive .NET Tutorials 2009

Disclaimer

The views expressed on this weblog are mine and do not necessarily reflect the views of my employer.

All postings are provided "AS IS" with no warranties, and confer no rights.

www.flickr.com
This is a Flickr badge showing public photos and videos from Robert Pickering. Make your own badge here.