Marcus doing new stuff

Two big things will (or are in the process of) happen this weekend.

The first is that I have gone over to the dark side. Yes, I know, I couldn’t resist anymore. The temptation was too great.

overview-gallery4-20090608[1]

I have bought a MacBook Pro. And have just installed it – that process was so smooth. I want to do it again!

OK – the next thing is that I will speak at a conference for the first time ever. Actually, it’s an Un-conference for alt.net Sweden. And it’s a lightning talk, but that only makes it harder, I think. 10 minutes – it’s not much.

The subject is “Let Fluent NHibernate test your mappings.” And it relates to some of my recent findings.

I know that I have spoken some bad words about Apple, so I suspect some pretty harsh comments from...

Read More

AutoMapping with FluentNHibernate

I came across this post by Ayende which perfectly captures my goal for achieving persistence ignorance:

“After that, you are done. Just create an entity in the proper place, hit the /database/create and have a lot of fun.”

I particularly enjoy the “fun” part of this quote! My aim is to configure conventions and then simply code the model as I desire, allowing the framework (NHibernate in this case) to handle the storage details.

The Fluent NHibernate framework has been updated since Ayende’s post. I explored the documentation, including AutoMapping, Conventions, Available Conventions, and discovered some shortcuts. Additionally, this article explains how to transition from the old convention style to the new one.

I’ve put together an updated example inspired by Ayende’s post, including a feature for automatically setting cascades for OneToMany and ManyToMany relationships.

Here is the most...

Read More

Pastie – Your Online Clipboard

If you’re looking for a simple way to share code snippets without the hassle of email or chat messages, Pastie is a great tool.

Just visit the site, paste your code, optionally select a programming language, and you’ll receive a URL to share your code snippet. It’s a handy way to quickly get feedback or collaborate with others on coding problems.

Read More

Fluent NHibernate CheckReference Throws Expected ‘X’ but Got ‘XProxy’

Lately, I’ve been working extensively with Fluent NHibernate and encountered a recurring issue.

When setting up a mapping test with PersistenceSpecification<T> to test a reference (using CheckReference, for instance), I often get the following exception:

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

This issue arises because NHibernate generates a proxy class, which causes problems when performing equality tests on that class. To address this, I found a base class that resolves this problem, provided by the Hibernating Rhinos (what a name!).

You can read more about this solution here or check out my code here.

Read More

Vasa Band and Saturday Night Success

This weekend, the band I play in, the Vasa Band, had the privilege of performing at the Salvation Army’s regional congress in Örebro. We were invited to participate in the musical festival on Saturday.

In preparation, a few of us brainstormed ways to bring something new and different to the performance. We drew inspiration from some great bands and put together a short program featuring music from our latest CD – Priority.

Our performance was very well received, making a significant impact. More importantly, we felt that many people experienced the presence of God and his message through our music. This is always our greatest hope and longing, and it was particularly evident on Saturday.

It feels wonderful to continue this journey with my fellow band members.

I’ll try to upload some photos from the evening soon.

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 NHibernate Mappings with Fluent NHibernate

After spending a few days working with Fluent NHibernate, I’m finding it to be a fantastic tool. One feature that stands out is the ability to test your mappings. This feature is especially useful as it allows you to switch to an in-memory database, such as SQLite, which speeds up your tests and eliminates the need for a complex database setup.

For a solid introduction to NHibernate and Fluent NHibernate, check out the articles by Gabriel Schenker from Hibernating Rhinos. These articles cover mapping testing and are available here (Part 1, 2, and 3).

And I love this quote: “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 a brief experience with NHibernate, I quickly realized that managing XML files for mapping instructions can lead to several issues. XML files lack compile-time checking and can create discrepancies between code and configuration.

The solution? Fluent NHibernate. This library allows you to define mappings in code using a fluent interface, eliminating the need for XML configuration.

I recently explored their starter example and was impressed. The approach is intuitive and offers features that feel almost magical, such as auto-mapping. It aligns well with the idea of “letting 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.

These topics can be quite confusing, especially with modern syntax like lambda expressions. It’s challenging to make sense of something like () => { } at first glance.

The article by S. Desmedt offers a clear explanation and includes many links for deeper exploration. If you’re struggling with these concepts, this resource is a great starting point.

Read More

Implementing Unit Of Work with NHibernate

The more I work with NHibernate, the more I question why I wrote so much SQL in the past. It feels… unnecessary. Who said “stupid”? Not me…

Jimmy Nilsson once said, “I just want the database and storage problems to be a consequence of my domain model. I don’t want to think about it.” This aligns with one of the goals of Domain-Driven Design (DDD), and NHibernate is a key tool in achieving this.

I’ve been experimenting with NHibernate recently, and I’m genuinely impressed. While the mapping files can be complex initially and there are many tricks and traps to navigate, NHibernate is truly powerful.

Here are some resources that have been particularly helpful in my journey:

Read More