I have an nHibernate request using Criteria, and I'm trying to overlay a string on bool in the request itself. I did the same with casting a string to int, and this works well (DataField property β1β as a string):
var result = Session .CreateCriteria<Car>() .Add(Restrictions.Eq((Projections.Cast(NHibernateUtil.Int32, Projections.Property("DataField"), 1)) .List<Car>(); tx.Commit();
But I am trying to do the same with bool, but I am not getting the expected result:
var result = Session .CreateCriteria<Car>() .Add(Restrictions.Eq((Projections.Cast(NHibernateUtil.bool, Projections.Property("DataField"), true)) .List<Car>(); tx.Commit();
"DataField" is the string "True", but the result is in the empty list, where it should contain 100 elements with the property string "DataField" set to "True". I tried with the string "true" and "1", but the result is still empty.
[EDIT]
As noted below, I can check the string "True" or "False", but I would say that this is a more general question than just for Boolean ones.
Note that the idea is to have some kind of representation of the values ββof the key data values, where the value can be different types of data. I need a value table to contain all the data, so saving the data as a string seems like the cleanest solution!
I managed to use the method described above to store both int and double as strings, as well as to cast to the request, but I was not able to use the same method for DateDime and Boolean.
And for DateTime, it is imperative to have an actual DateTime object.
How can I do a translation from a string to bool, and a string in DateTime to work in queries?
thanks
code-zoop
source share