Gah! I have been unable to reproduce this in the trunk. On Jan 20, 6:27 pm, João Bragança <[email protected]> wrote: > I just got bit by this one too. I am dynamically building up a Linq > Expression to do address matching and it is generating an expression > that looks like ((address.Street.BeginsWith("First") == True) AndAlso > (address.City.BeginsWith("New York") == True)). I cloned this as > NH-2514 and will attach a failing test shortly. > > On Jan 17, 11:05 pm, jokedst <[email protected]> wrote: > > > > > > > > > Ok, I had a really hard to track down problem, and I couldn't find > > anything about it on the net so I thought I'd post it here. This is > > related to bug NH-2010 in JIRA, but it doesn't explain how to fix it, > > so here goes: > > > I repeatedly got this error: > > System.InvalidCastException: Unable to cast object of type > > 'System.Boolean' to type 'System.String'. > > at NHibernate.Type.AbstractStringType.ToString(Object val) in d: > > \CSharp\NH\nhibernate\src\NHibernate\Type\AbstractStringType.cs:line > > 32 > > at NHibernate.Type.NullableType.ToLoggableString(Object value, > > ISessionFactoryImplementor factory) in d:\CSharp\NH\nhibernate\src > > \NHibernate\Type\NullableType.cs:line 109 > > at NHibernate.Impl.Printer.ToString(IDictionary`2 namedTypedValues) > > in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\Printer.cs:line 68 > > at NHibernate.Cache.QueryKey.ToString() in d:\CSharp\NH\nhibernate > > \src\NHibernate\Cache\QueryKey.cs:line 216 > > at NHibernate.Caches.SysCache2.SysCacheRegion.GetCacheKey(Object > > identifier) > > > It tried to cast a bool to a string (e.g. "something = > > (string)theBool"). You can't do that. > > > The problem was this string: > > queryable = queryable.Where(x => x.IsInvoiceToSupplier == > > false); > > > It's not the "IsInvoiceToSupplier" that's the problem - it's the > > "false"! It works when you write it like this: > > queryable = queryable.Where(x => !x.IsInvoiceToSupplier); > > > Also, this: > > queryable = queryable.Where(x => > > x.IsInvoiceToSupplier == true); > > should be like this: > > queryable = queryable.Where(x => > > x.IsInvoiceToSupplier); > > > You'd think it'd generate the exact same bytecode, but nooo.... > > > So we need to be really careful with what we put in the "Where" clause > > on IQueryable:s. > > > Note that this problem only shows up if you have debug logging enabled > > or if you use query caching since the query cache key is generated > > from the generated text query. > > > I suppose this in not technically a bug in NHibernate, but rather how > > linq works and the interactions between them, but it was still a hard > > bug to track down.
-- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
