NHib Atleast One Check

PS
NHibernate doesnt have a way to check whether a List has atleast one item.
This kind of validation is important and if it fails, atleast the save should catch it.
This can be done with a neat Mapper extension and an on save listener.

//Register with the NH Configuration
configuration.SetListener(ListenerType.SaveUpdate, new HasAtleastOne.Listener());

//Use in the classMap
HasMany(x => x.Links).KeyColumn("Project_id").MustHaveAtleastOne();

//Test the code
var l = new HasAtleastOne.Listener();
var e = new Project();
l.TestSave(e);


code


Warning: count(): Parameter must be an array or an object that implements Countable in /home/cselian/public_html/blog/wp-includes/class-wp-comment-query.php on line 405

Leave a Comment