开发者

ICriteria - fluent nhibernate not producing inner join

开发者 https://www.devze.com 2023-04-01 00:02 出处:网络
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.

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


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"));
0

精彩评论

暂无评论...
验证码 换一张
取 消