Problem with NHibernate Validator

28 views
Skip to first unread message

Jamie Penney

unread,
Nov 23, 2009, 6:51:12 PM11/23/09
to nhusers
Hi All,

I am having an issue getting a basic example of Nhibernate Validator
working using version 1.2.0 beta 3. I have a very basic NHibernate
project, with an Entity called Category:

public class Category
{
public virtual int CategoryID { get; set; }
[NotNullNotEmpty]
[Length(50)]
public virtual string CategoryName { get; set; }
....
}

As you can see, I have two validator Attributes on the CategoryName
property. I load up the validator using the following code:

private static ValidatorEngine _validator;
public static ValidatorEngine Validator
{
get
{
if(_validator == null)
{
_validator = new ValidatorEngine();
_validator.Configure(new NHVConfigurationBase());
}
return _validator;
}
}

and use it like this:

var issues = Validator.Validate(category);

The issues array is always empty, even when I set
category.CategoryName to null. Can anyone shed some light on what I
might be doing wrong? I wanted to just do a simple proof of concept,
but this doesn't seem to be working. Google has given me nothing so
far.

Cheers,
Jamie

Fabio Maulo

unread,
Nov 24, 2009, 6:40:44 AM11/24/09
to nhu...@googlegroups.com
Jaime,
can you read this serie ?

You are using an empty configuration.
btw if you remove this _validator.Configure(new NHVConfigurationBase()); all should work.
anyway have a look to the series to learn something more about NHV.

2009/11/23 Jamie Penney <freak...@gmail.com>

--

You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.





--
Fabio Maulo

J Penney

unread,
Nov 24, 2009, 3:50:35 PM11/24/09
to nhusers
Turns out this wasn't the issue at all. I had an issue with my
solution file which meant it wasn't building my NHibernate project, so
the attributes I had just added to that class were not being compiled
in. I've been reading that series of yours, it is full of useful
information.

Cheers,
Jamie

On Nov 25, 12:40 am, Fabio Maulo <fabioma...@gmail.com> wrote:
> Jaime,
> can you read this serie ?http://fabiomaulo.blogspot.com/search/label/Validator
>
> <http://fabiomaulo.blogspot.com/search/label/Validator>You are using an
> empty configuration.
> btw if you remove this _validator.Configure(new NHVConfigurationBase()); all
> should work.
> anyway have a look to the series to learn something more about NHV.
>
> 2009/11/23 Jamie Penney <freakbo...@gmail.com>
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com >
> > .

Fabio Maulo

unread,
Nov 24, 2009, 5:36:08 PM11/24/09
to nhu...@googlegroups.com
btw don't use the empty configuration.
instead use the default Xml conf or Loquacious (the fluent conf); in practice the usage of _validator.Configure(new NHVConfigurationBase()) and use only _validator is the same and can work only with attributes.
The empty conf has some defaults and is important to know which is the behaviour.

Where possible (always IMO) try to avoid the usage of attributes: you don't need a reference to NHV in your domain.

2009/11/24 J Penney <freak...@gmail.com>
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.





--
Fabio Maulo

Reply all
Reply to author
Forward
0 new messages