views:

1401

answers:

3

Has anyone tried the ActiveRecord Intro Sample with C# 3.5? I somehow have the feeling that the sample is completely wrong or just out of date. The XML configuration is just plain wrong:

<add key="connection.connection_string" value="xxx" />

should be :

<add key="hibernate.connection.connection_string" value="xxx" />

(if I understand the nhibernate config syntax right..)

I am wondering what I'm doing wrong. I get a "Could not perform ExecuteQuery for User" Exception when calling Count() on the User Model.

No idea what this can be. The tutorial source differs strongly from the source on the page (most notably in the XML configuration), and it's a VS2003 sample with different syntax on most things (no generics etc).

Any suggestions? ActiveRecord looks awesome..

A: 

Delete the "hibernate." part for all configuration entries. Your first example is the correct one.

Gilligan
This then leads to the following error:"Error adding information from class ActiveRecord.Post to NHibernate. Check the inner exception for more information"As long as the hibernate. part is in the config, I at least can call ActiveRecordStarter.Initialize() without exceptions
Tigraine
Odd. I would check one of two things, then:1) what version of ActiveRecord are you using?2) Is there a typo or missing key in your configuration file?
Gilligan
I just started by downloading the lastest versions from the Castle.ActiveRecord page some hour ago. And got their sample.. that's what I installed: http://www.castleproject.org/castle/download.html
Tigraine
+1  A: 

The 'hibernate' portion of the key was removed in NHibernate version 2.0. This version is correct for NHibernate 2.0 onwards:

<add key="connection.connection_string" value="xxx" />

Edit: I see that the quickstart doesn't come with the binaries for Castle and NHibernate. You must have downloaded the binaries from somewhere; it would be helpful if you could provide the version number of your NHibernate.dll file.

Confusingly, at least SOME of the quickstart has been updated to be current with NHibernate (NH) 2.0, but the latest 'proper' Castle release is still the 1.0 RC3 (almost a year old now), which does not include NH 2.0.

You can go two ways. You can continue using Castle RC3 and in this case you will indeed need to add the 'hibernate' prefix to your configuration entries. Or you can download a build of Castle from the trunk, which should be running against NH 2.0. The problem with the latter approach is that some of the other breaking changes introduced in NH 2.0 might not be fixed in the quick start.

Paul Batum
+1  A: 

(This was too long for a comment post)

[@Tigraine] From your comments on my previous answer it looks like the error lies not with the configuration, but with one of your entities. Removing the "hibernate" corrected the configuration so that it geve you the real error, which appears to be that the entity "Post" is not properly attributed for ActiveRecord to create its mapping.

If you further down in the error that it gives, it likely has some details as to what about "Post" failed.

Some common things include:

  • THe class does not have the [ActiveRecord] attribute.
  • There is no property with the [PrimaryKey] attribute.
  • There is no matching table called "Post" (or "Posts" if PluralizeTableNames is "true").
  • There is no matching column(s) for attributed properties.
  • Your attributed properties and public methods are not virtual (this one kills me all the time).
Gilligan
Thanks, great answer! I'll try that asap :)
Tigraine
Maybe I got an old version. But my config keys HAVE to start with hibernate.XX. I could get it to run now. still the config in the tutorial is wrong (for me)
Tigraine
Sounds like an older version. At least you have things working. That is good to hear!
Gilligan