You can follow me here:
http://twitter.com/darioquintana
Thanks to Angel for share this video, but it’s on plain English, similar to Anglish
You can follow me here:
Thanks to Angel for share this video, but it’s on plain English, similar to Anglish
NHibernate (as a lot of frameworks of IoC) has reflection optimizers to create objects, set and get field/properties. So you don’t have to be worried about that matter: NHibernate isn’t using a plain reflection approach.
This could be an very good argument at the time to “sell NHibernate” to: a customer, a Company or my boss. Have a look on the results of a demo proyect:

As you can see the use of the reflection optimized is faster than the use of reflection. Obviously direct access is the fastest way, but impossible to use in a ORM like NHibernate (as in many other frameworks).
You can download the demo application here.
Thanks to Fabio Maulo to make this example looks nicer. Gracias che !
Here is the promised documentation of NHibernate.Validator 1.0.0 Alpha1. You can download it here in different formats: html, pdf and the API via .chm
A lot time ago this blog bring up to us interesting posts about NHibernate, I recommend to you have a look, there a bunch of nice HowTo’s.
For who isn’t familiar with NHibernate Validator: it’s a cool framework to validate objects anywhere at our applications. That’s it.
Now, how we can integrate this tool in order to validate the objects before save/update at Db4o? The answer is: very easy. You can download the code at the end of the post.
Remember you can configure NHibernate Validator using .Net Attributes or Xml files. In this case we will se how to do it using the first approach. The class Customer should look like this:

Now how to make the integration using a little helper class ? Like this:

As you see, with a little helper class we can configure the integration with only one line of code, very easy. In this line the method Initialize register before events on the Save/Update at the Db4o Core.
Now, let’s see the validation in action, the below example show the application trying to save an object with an invalid state:

So when the Save/Update is going to happen, first of all, NHibernate Validator check if the entity is into a valid state, if it’s not, an InvalidStateException is thrown, then Db4o wrap it with an EventException, so we have to unwrap the exception to recover the invalid values to display to the user. Would be nice that Db4o don’t wrap the exceptions, but this topic was discussed on this thread.
So, was easy to integrate NHibernate Validator with Db4o. Wasn’t it ?
I was waiting this release from the Db4o for long time, and the people whom folow to Db4o I think as well.
For the people that are not so familiar, Db4o run onto Java and .Net Platforms. The main development is made at Java, and then using this amazing tool: Sharpen, they make the conversion to nice C# code, although Db4o.Net is not 100% converted, the most part of it it’s.
I hope it helps !
Finally you can download the first official drop of NHibernate.Validator. This project began as a port of Hibernate.Validator project, but later was growing up on features, and now has a quite different API, optimized to validate objects integrated with NHibernate and objects of any part of our application. NHibernate Validator allow us to validate objects configured using .Net attributes or nhv.xml files.