/Images/MainImage/Marcus Hammarberg.jpg finns inte.

NHibernate

2010-02-11 07:50

System.BadImageFormatException: Could not load file or assembly 'System.Data.SQLite'

I ran into this problem when I tried to re-open a solution I did a while back when labbing with Fluent NHibernate and SQLite.

Behind the cryptic error message lies and easy solution; I was running the 32-bit version of the SQLite-driver and runtime. That' doesn’t fly on my Windows 7 64-bit machine.

Here is a more through description and here is a link to the latest version of SQLite that will get you all the version (32 and 64 bits) of the SQLite.


Postad av Marcus Hammarberg

Kommentarer (1)   Kategorier:  Tools    .NET    NHibernate



2010-01-28 09:19

ASP.NET MVC, StructureMap and … TDD?

I’ve been playing around a bit with ASP.NET MVC and StructureMap (an IOC container). It all looks very nice and works wonder. During this I ran into an excellent blog post by Elija Manor on wiring StructureMap and ASP.NET MVC together. Beware of the favicon-problem though.

Again – i use NHibernate and Fluent NHibernate which so much nicer than the XML-stuff. The critics to Fluent NHibernate says that you cannot reach all functionality from Fluent NHibernate, but here is an example on how to set specific properties in your configuration. Helped me through this example.

Also found some great code examples from the TekPub NHibnernate series here.

OK – I've added “TDD?” in the title. I love TDD and it’s my preferred way of doing code, but I have a problem (to quote a thinker). I think TDD doesn’t help my through the broader strokes of my application.

Where do I start? How do I use the test to know that it’s time to add an repository, or an IOC Container? Do I TDD the IOC-code?

I asked the Swedish ALT.NET group a question and got some great tips, mostly they pointed me to BDD and those ideas. I also liked the idea of the Walking skeleton.

But I’m still confused. Can TDD really help you to design a system from the bottom up, or top-down (BDD) for that matter? Will the design be improved by the TDD-design technique? I’m not sure.

For now, my thinking is that it’s better to create a very simple design (MVC + repositories + IOC) to get your “skeleton to walk”, maybe with a functional/integration test that verify the functionality.

With that foundation in place it becomes easier to add some meat to the bones (is this skeleton metaphor taken too far yet?) with the normal TDD techniques and patterns.


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  .NET    Agile    TDD    NHibernate



2009-11-06 11:55

ÖreDev day #5 – keynote and morning

Information overload and managing flow

The last day kicks off with a keynote given by Scott Hanselmann, who is one of my "heroes" if you like. I always wanted to see him live, he is usually informative and really funny. Here is some off his tips on the subject:

  • Effectiveness – doing the right things
  • Efficiency – doing the things right (jumping off a cliff in a efficient way :))
  • Triage – sort information. Don’t leave things in your inbox
  • Do it – drop it – delegate it – defer it = pick one.
  • Sort your data streams (twitter, email, colleague) into Signals and Noise
  • Email that you’re cc:ed on are not as important To:
  • Mailing list
  • Don’t check emails in the morning - “If you are the fastest responder to a problem, you will get all the problems.”
  • Check email three times a day – for 20 minutes each.
  • You cannot beat the system by putting in more hours.
  • Use the Pomodoro Technique and schedule your work (emailing, phoning, blogging, coding etc.)
  • Audit your input and streamline it.
  • “You can’t cut if you don’t measure” – Scott Hanselmann
  • Tools
    • Rescue Time – introspective retrospectives
    • 43 folders looks quite messy but powerful
    • Sync to paper – check out http://pocketmod.com/
    • Write things down that you want to do during a week. And check that the list is done or not at the end of the week
    • Evernote
    • Remember the milk instead of todo.txt
    • Use email rules as above (to:/cc: and calendar invites)

This was very funny and informative. The funniest is that he did basically the same as the Zen-guru Marc Lesser. But oh so different…

The Pair Programming Show

This promise to be great. The first slide says “How to teach pair programming?” It looks to be, just as the title, as a show. With props and the whole thing – nice. The presentation is done by Niclas Nilsson and Hans Brattberg

Also they promise to show some of the bad things that we can experience when teaching/learning pair programming.

Pair programming is about; communication, learning and communication. So be patient, split time with keyboard equal, talk, not show. It’s hard! But the only way to get everybody up to speed.

Without an engaged navigator you don’t collaborate and share mind. Then you get any of the advantages of pair programming. A complicated operation is always performed with two doctors. Would you rather have one?

There are now giving some great points on why pair programming is feasible and economical. For example this chart.

It’s easier to stand up for code quality and not “hacking” when you are two people together… Also it’s harder to hide technical debt.

They had an excellent summary slide of benefits with too much for me reloop here.

Breaking out of dependency hell

This talk is given by a tired Ayende. He has promised to use his designated victim method… Better stay alert.

He talked about the use Dependency Injection, Inversion of Control containers and Convention over configuration to manage solution complexity.

Using a Inversion of Container will make us feel like you lose control of your dependencies. And that is the whole idea – if you micro-manage your dependencies will give you a static system that is hard to change (Open-Close-principle, open for extension but closed for modification).

Another benefit from using an IoC is that you get opportunity to use aspect-oriented programming, to handle cross cutting concerns.


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  Tools    .NET    Agile    NHibernate



2009-11-04 09:23

ÖreDev day #2 – NHibernate in practice

Now it’s NHibernate with Stephen Bohlen, who is aiming to cramming in all (kinda…) of the screencast on www.summerofnhibernate.com in 4 hours.

I think I’ll just sit back and try to learn this, because this guy is probably paid by the word :)

OK – closing in on the end. I really enjoyed this presentation but it would have benefitted from being longer, a whole day. It felt a bit rushed and we didn’t get as far as I would have reached. Although the material covered was great and well presented. And now I always have the www.summerofnhibernate.com to run back to.

I learned something about TDD and unit tests. Always ask:

“What can we safely assert?”

And the answer should be:

“Only the values I’ve set in the test code”

This is especially useful doing “unit tests” against the database (ie. integration tests).

If you write a test that searches for people with first name equal “FIRST NAME”, the only thing you safely can check that returned people contains is that first name equal “FIRST NAME”.


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  NHibernate



2009-10-19 17:31

Sharp Architecture presentations

Found a great presentation on the excellent S#arp Architecture framework. The presentation is given by Billy McCafferty who is the father of the framework.

It’s so good – you just want to start to code with it. It’s a bit “rough” but I suspect that we will see some major improvements in the “developer experience” in the near future.

Also – tomorrow Håkan Alexander will present the framework at Elevate. It will be great to see how the framework will be received among the Avegean. I would cast my vote on big success…


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  .NET    Agile    NHibernate



2009-09-09 09:16

AutoMapping with FluentNHibernate

I ran across this post by Ayende and it pretty much sums up where I want to reach with my persistence ignorance efforts:

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

I of course like the fun-part of the quote the most. :) But seriously – that what I want to reach – to configure my conventions. And then simply code the model as I want it and let the framework (NHibernate in this case) figure out how to store it.

Well, as it seems, the Fluent NHibernate framework has been updated since the Ayende post. So I’ve read, and read, and read and discovered some shortcuts. By the way – here is an article on how to make the transition from the “old” convention-style into the new.

I have put together an updated sample for what Ayende did in that post above. I also added a feature to be able to automatically set cascades for OneToMany- and ManyToMany-relationships.

Here you’ll find the most important parts of the code.

[UPDATED]
Here is the complete sample.

 

Did I mention that I LOVE Fluent NHibernate? Well I do!


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  .NET    DDD    NHibernate



2009-09-08 15:33

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.


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  .NET    NHibernate



2009-09-03 15:14

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


Postad av Marcus Hammarberg

Kommentarer (0)   Kategorier:  Tools    .NET    NHibernate

  RSS Feed

Marcus Hammarberg

I am a consultant with Avega working with Microsoft, .NET, system design and agile system development. When i am not working most of my time is taken up by the Salvation Army and playing my instrument, the euphonium. I am married to Elin since july 2006 and we are living in the middle of Stockholm.. In january 2008 our son Albert was born and have taken a prominent place in our hearts and lives.


Kontakt