You created http://216.121.112.228/browse/NHLQ-94 for the contrib- project NHibernate.Linq, the old LINQ provider. If you actually have this problem with the new built-in provider, close that issue and create a regular NH issue.
HTH, Stefan On Mar 7, 6:03 pm, sianabanana <[email protected]> wrote: > I have this problem too. > > Im not sure how it relates tohttp://216.121.112.228/browse/NH-2010 > > I have recently upgraded to nhibernate 3 and at the same time switched > from linq to nhibernate to nhibernates own linq namespace. > > I have a suite of tests set up and ran them and many began to fail > > I have tracked it down to a simmilar issue to what you have said > above. > > I pass in a bool variable in to my method - active. > > and then do .Where(x => x.Active == active) > > This way if i want active ones i can get them, and if i want inactive > ones, then it will get those. > > I get Unable to cast object of type 'System.Boolean' to type > 'System.String' > > As a temporary mesure, i have had to conditionally set Where(x => > x.Active) or Where(x => !x.Active) to make this work. > > From reading the above linked bug report, im not sure how they relate? > Is this definately the same problem? > > On Jan 18, 7:05 am, 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:Unabletocastobjectoftype > > 'System.Boolean' totype'System.String'. > > at NHibernate.Type.AbstractStringType.ToString(Objectval) in d: > > \CSharp\NH\nhibernate\src\NHibernate\Type\AbstractStringType.cs:line > > 32 > > at NHibernate.Type.NullableType.ToLoggableString(Objectvalue, > > 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 tocasta 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.
