vondip
vondip

Reputation: 14039

ICriteria - fluent nhibernate not producing inner join

I am developing a small web application, using nhibnerate as my DAL. I have to classes that I wish to select from, using a simple ICriteria.

This is a sample of my code:

var criteria = CurrentSession.CreateCriteria(typeof(School))
    .CreateAlias("students", "s")
    .Add(Restrictions.Eq("s.Name", "Charley"));

From some reason this code generated a query with no inner join. I have only one table selected from.

How can I solve this?

Thank you

Upvotes: 1

Views: 618

Answers (1)

Jamie Ide
Jamie Ide

Reputation: 49281

Oenning's comment may be the answer but you should also specify the join type in CreateAlias:

var criteria = CurrentSession.CreateCriteria(typeof(School))
.CreateAlias("students", "s", JoinType.InnerJoin)
.Add(Restrictions.Eq("s.Name", "Charley"));

Upvotes: 2

Related Questions