I'm new to NHibernate so I'm sure that I'm just missing something fundamental.
I have an table called Issue that has a ParentId column. The ParentId can refer to different tables (i.e. - Project or Customer, etc.) How can I do that query in NHibernate so that I can show only the Issues that belong to Project. Here is what I've tried.
DetachedCriteria dCriteria = DetachedCriteria.For<Issue>("issue")
.SetProjection(Projections.Property("ParentId"))
.CreateAlias("Project", "project", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.EqProperty("issue.ParentId", "project.Id"))
;
var issues = Session.CreateCriteria<Issue>("issue")
.Add(Subqueries.Exists(dCriteria)).List<Issue>();
return issues;
my mapping looks like this. Notice I don't have any reference to the parent object because I don't know what it will be.
<class name="Issue" table="dbo.Issue" lazy="true">
<id name="Id" column="Id">
<generator class="assigned" />
</id>
<property name="ParentId" column="ParentId" />
<property name="Name" />
<property name="Description" />
I would appreciate any guidance.
perhaps I should explain a little more. I have a grid of all issues and I want to show a type column so we know what type of issue (project, etc.) the column doesn't serve any other purpose than this one display so I don't believe it's valid to add it to the database. In SQL it's easy enough to filter the data via the join or using Exists. There must be a similar method in NHibernate so I don't have to loop through every Project for all it's issues.