Hi! I have a (several actually) relationship between two objects, the parent object is a User and the child object is an Incident. There are four relationships defined between User and Incident:
- Property User
_
created of Incident refers to a User who created the Incident - Property User
_
modified who modified the Incident - User
_
reported and finally - User
_
responsible
All these four properties of Incident references a User object. Like this in the mapping:
<many-to-one name="User_created" class="User, WebbData" fetch="select">
<column name="created_by" not-null="true" />
</many-to-one>
<many-to-one name="User_modified" class="User, WebbData" fetch="select">
<column name="modified_by" not-null="false" />
</many-to-one>
<many-to-one name="User_reported" class="User, WebbData" fetch="select">
<column name="reported_by" not-null="true" />
</many-to-one>
<many-to-one name="User_responsible" class="User, WebbData" fetch="select">
<column name="responsible" not-null="false" />
</many-to-one>
I want to write a nHibernate expression to fetch all Incidents created by a specific user but I don't know how to write this expression... This is what I got so far:
return session.CreateCriteria(typeof(Incident))
.CreateCriteria("User")
.Add(Expression.Eq("Id", UserID))
.List<Incident>();
but how the heck do I tell nHibernate that it should use the User_
created relation and not one of the other three?