I've got an easy question, i hope i will be luckier than latest time i asked a generical quesiton in this forum (although i know that my problem was not easy to be understood)
In order to avoid boring you with my particular classes, i'm exposing my current situation with a similar example
Let's assume the following class:
Code:
Class Student
{
public int StudentId;
public string FirstName;
public string MiddleName;
public string SecondName;
}
I'm assuming that in case StudentId were primary key, mapping should seem like this:
Code:
<class name="Student" table="STUDENTS">
<id name="StudentId">
<column name="StudentID"/>
<generator class="native"/>
</id>
<property name="FirstName"/>
<property name="MiddleName"/>
<property name="SecondName"/>
</class>
But, what if i wanted to make FirstName/MiddleName/SecondName an unique index?
I've tried with following:
Code:
<class name="Student" table="STUDENTS">
<id name="StudentId">
<column name="StudentID"/>
<generator class="native"/>
</id>
<property name="FirstName" unique-key="NAME_MUST_BE_UNIQUE"/>
<property name="MiddleName" unique-key="NAME_MUST_BE_UNIQUE"/>
<property name="SecondName" unique-key="NAME_MUST_BE_UNIQUE"/>
</class>
I'm using _session.SaveOrUpdate, but i still seeing unique constraints violated. After digging into forum, i've started to think that unique-key it's just intende to crate tables, but it's unuseful for already created tables processing
Does NHibernate provide any way to (let say) check FirstName MiddleName and SecondName and insert in case there were not violating unique constraing and update when they were?
I'm working on SQLExpress, but it's intende to move to Oracle in near future
Thanks for any helpful answer you can provide me.