开发者

Nhibernate Criteria join with multiple conditions

I can't seem to find any solid answer to the problem, I'm hoping someone will be able开发者_开发问答 to help me here.

Sample query:

select * from A a inner join B b on a.Id = b.Id Or a.Date = b.Date

Basically I want to know if it's possible to implement the second part of the join condition using criteria, and if it is possible, how to go about it. If anyone can please let me know, that will be great! Thanks a bunch!


It might be, but that query is more clear written in HQL:

select a from A a, B b where a.Id = b.Id or a.Date = b.Date

As you can see, it's almost the same as the SQL.


Unfortunately you cannot define ANSI syntax joins with NHibernate. With NH2 and onward you can define them on HQL using a WITH clause and i say so because if you use Diego's solution you will have to set up a ISNULL OR pattern in your queries if you want to perform multiple joins.


to add conditions, use Expressions. For the OR disjunction, its less complex if you use Expresion.In

session.CreateCriteria(typeof(A), "a").CreateCriteria("B", "b", NHibernate.SqlCommand.JoinType.FullJoin)
                             .Add(Expression.Eq("a.Date", a.Date))
                             .Add(Expression.Eq("b.Date", b.Date))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜