Fluent NHibnerate CheckReference throws Expected ‘X’ but got ‘XProxy’

I have been playing around quite a lot with Fluent NHibernate lately and ran into this problem a couple of times.

What happens is that when you set up a mapping test with PersistenceSpecification<T> that tests a reference (with CheckReference for example), an exception is throw like this:

System.ApplicationException: Expected ‘Marcusoft.Product’ but got ‘ProductProxy…’ for Property ‘Product’

This has to do with that NHibernate creates a proxy-class and doing Equality-test on that class. I have picked up a base class that “fix” this problem from the Hibernating Rhinos (my god! what a name…)

You can read about it here or read my code here.

Read More

Vasa Band and Saturday night success

This weekend the band I play in, the Vasa Band, had an opportunity to play at the Salvation Army regional congress in Örebro. We were invited to play in the musical festival at Saturday.

When we learned about this a few of us started to think in how we could make something new and different. And so we borrowed ideas from some great bands and put together a short program with music from our latest CD – Priority.

It was very well received and we really made a big impact. But what felt very good was many people felt the presence of God and his message to them as we played. This is always our greatest hope and longing. And this Saturday it was very obvious.

Feels really good to continue on that road with my fellow bandsmen/women.

I’ll try to upload some photos...

Read More

Dos-script to delete all Visual Studio Intermediate files

I have a USB-stick which acts as my backup. As I program a lot compilation and unit testing produces a lot of trash (.pdb, Test Results, obj-files etc). I don’t want or need a backup of those.

Today I found a short script that removes those file. Since I have folders named “bin” I want to keep I tweaked it a bit into this:

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S Debug') DO RMDIR /S /Q "%%G" FOR /F "tokens=*" %%G IN ('DIR /B /AD /S _Resharper*') DO RMDIR /S /Q "%%G" FOR /F "tokens=*" %%G IN ('DIR /B /AD /S TestResults') DO RMDIR /S /Q "%%G" FOR /F "tokens=*" %%G IN ('dir /b /A /S *.vsmdi') DO RMDIR /S /Q "%%G" 

I don’t know if you are like me and don’t know the first things of DOS....

Read More

Test NHibnernate mappings with Fluent NHibnernate

After a couple of days in the Fluent-world I am taking to it as a fish to water.

One of the features that I am tried out and really think will be helpful is the ability to test your mappings. Especially nice is that you in your tests can switch to a in-memory database (with SQLite) so that your test run faster, and without having to setup a database.

I found a good introduction to NHibernate and Fluent NHibernate by the Hibernating Rhino Gabriel Schenker that also introduces mapping testing. Read it here (part 1, 2 and 3).

Love this quote by the way: “if you continue to implement your own data access code you are stealing (money) from your customer

Read More

Get rid of your xml – go Fluent NHibernate

After my very short experience with NHibernate I have already come to realize that lots of problems can arise from and in the XML-files that contains the actual mapping instructions.

Just the fact that they are XML gives you the classical problem of no compile-time checking and the possibility of calling things differently in the code and configuration.

Well, here is the solution; Fluent NHibernate. Their solution is simple – do it in code, in a fluent interface-style.

I just ran through their starter example and I like it. A lot. And some of it is almost magic. A good way to “let the storage issues be a consequence of the domain model”

Read More

First stop for learning events, delegates and anonymous methods

I found this great article about events, delegates and anonymous methods.

I always get lost in these matters and now-a-days you can have some really funky syntax with lambdas and everything (I mean who can honestly say that: “() => { }” is read- and understandable. Honestly).

OK – this guy (can’t find his name) has done an excellent write-up, with lots of links to other places if you want to go deep (but that’s really deep, bottomless if you want).

Read More

Implementing Unit Of Work with NHibernate

The more I work with it the more stupid I feel around what I have been doing before; why have I written so much SQL? It feel just … unnecessary. Who said stupid? Not me…

Jimmy Nilsson said something like; “I just want the database and storage problems to be a consequence of my domain model. I don’t want to think about it”.  And that is one of the goals with DDD and the solution is, for example, NHibernate.

I have been doing some labs with NHibernate the last couple. And as often with me – I think I am in love. NHibernate really rocks. The mapping files are quite hard to chew off at first and I suspect that there are many tricks and traps for me to find. But still – so beautiful.

Of course the Net has helped me a lot on my...

Read More

Object-oriented database – worth a try

I have been doing a very small lab with an object-oriented database, db4o, and I am very impressed indeed.

The concept a first is a bit hard to grasp since there are no tables, no SQL and hence no mapping going on. You simply store your objects.

Of course the trick is to query them back, but the excellent db4o-crew and chunking out code every now and then and for example the current release includes full support for LINQ which gives you and excellent programming experience.

I am still very much a newbie and have some un-answered questions on how data and class definitions evolution is handled. But it looks cool, very cool.

Just say it loud for yourself: “No more SQL. No more mapping.” Yeah, you like it, admit it.

Read More