-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Fluent Nhibernate Expression.OR
PostPosted: Thu Apr 14, 2011 2:20 pm 
Newbie

Joined: Thu Apr 14, 2011 2:02 pm
Posts: 2
Hello people!

I need a big help with Fluent NHibernate.

Follows, I got this Query:

Code:
select * from tabela
where
   (dataBegin between '2011/04/13 13:00:00' and '2011/04/13 14:00:00'
   or ((dateadd(minute,tempo, dataBegin) >= '2011/04/13 13:00:00') and
      (dateadd(minute,tempo, dataBegin) <= '2011/04/12 12:00:00') )


I've tried this:

Code:


ICriteria query = session.CreateCriteria(typeof(tabela))
                   .Add(Expression.Between("data", dataBegin, datafim))
                   .Add(Expression.Or(
                        (Expression.Sql("dateadd(minute,duracao, dtInicio) >= ? ", dataBegin, NHibernateUtil.String))
                        (Expression.Sql("dateadd(minute,duracao, dtInicio) <= ? ", dataEnd, NHibernateUtil.String))
                        ))
IList<tabela> listevento = query.List<tabela>();


But is this way, wrong.
Code:
select * from tabela
where
   (dataBeginbetween '2011/04/13 13:00:00' and '2011/04/13 14:00:00'
   and ((dateadd(minute,tempo, dataBegin) >= '2011/04/13 13:00:00') OR
      (dateadd(minute,tempo, dataBegin) <= '2011/04/12 12:00:00') )



Any help?


Top
 Profile  
 
 Post subject: RESOLVED Re: Fluent Nhibernate Expression.OR
PostPosted: Thu Apr 14, 2011 4:02 pm 
Newbie

Joined: Thu Apr 14, 2011 2:02 pm
Posts: 2
I got people really needed this command Expression.Conjunction().



Code:
ICriteria query = session.CreateCriteria(typeof(tabela))

     .Add(Expression.Between("data", datainicio, datafim))

     .Add(Expression.Or(
          (Expression.Between("data", datainicio, datafim)),
           Expression.Conjunction()
                      .Add(Expression.Sql("dateadd(minute,duracao, data) >= ? ", datainicio, NHibernateUtil.String))
                      .Add(Expression.Sql("dateadd(minute,duracao, data) <= ? ", datafim, NHibernateUtil.String))
          ))

IList<tabela> retorno = query.List<tabela>();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.