I have a simple entity that has an Id (the primary key) and a string name. I'm looking for a way to tell nHibernate not to allow duplicate names in the table.
I'd like to have an Add method that can take a new entity (with Id = 0), and if necessary add the new entity & update Id. This works now. If the name already exists in the table, I want to simply update Id and return the existing Id.
I'd like to be able call it like this:
Foo foo = new Foo(name); // foo.Id = 0 FooRepository.Add(foo);
.. and afterwards foo.Id <> 0 and it was either added or an existing foo.name was found and its Id was returned.
thanks/jf