0

I've got a int column mapped as Boolean type in domain objects. Everything was looking good until today where we noticed when doing a QueryOver on the bool property the actual SQL generated is not to the liking of SqlServer.

The queryOver looks like below:

.Where(Restrictions.On<OrderLine>(ol => _orderLineAlias.Approved).IsLike(true));

And the SQL for that is,

select * from Orderline where Approved like 'true'

Hope you can see the problem here, as the column's data type is int, this wont return me anything. Changing the DB data type or that of the Entity class is not an option.

6
  • time to go back and change your db model.. why would you keep them different Commented Aug 10, 2011 at 9:56
  • heh..good idea..but not going to work as there is a lot of legacy logic dependent on this . Commented Aug 10, 2011 at 10:12
  • legacy code aginst your dB.. hmm.. Commented Aug 10, 2011 at 10:59
  • 2
    IsLike with an int??? There is only a like for strings. Commented Aug 10, 2011 at 12:50
  • @Stefan, i was modifying this code someone else has written and figured it was done all wrong. Thanks for pointing that out :) Commented Aug 10, 2011 at 13:54

2 Answers 2

3

Have you tried:

    QueryOver<OrderLine>().Where(x => x.Approved == true)

?

Sign up to request clarification or add additional context in comments.

Comments

0

Did you try something on the lines of the following in the configuration file?

<property name="hibernate.query.substitutions">true 1, false 0</property> 

Link to NH documentation on this topic

4 Comments

thanks, but it does not make any difference. have or not the same sql syntax is generated. Probably that only works with LinqToHibernate. I'm using QueryOver in this instance.
I have been using it with HQL (call me dinosaur :) ) and it works fine. As another suggestion I would create another property which just acts as a convertor for bool<->int where int property/field is mapped to the underlying column whereas the bool property is used by UI/anything else.
Also found something that matches your problem stackoverflow.com/questions/5063541/…
Thanks Vijay..i tried adding a different property as well but same result. The issue is, the expression tree is built before the property reaches its' internals. So if we refer the Bool value in the QueryOver the sql is still going to be the same. As a temporary solution i'm gonna have two properties (int , bool) mapped to the same column and use Int one inside the QueryOver. I believe this has not been reported as a issue with QueryOver in jira. I wil try to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.