views:

81

answers:

2

Hi

Come across an issue when doing a string compare as part of the where section of a linq expression against LINQ for NHibernate.

from x in NhibernateObject
where x.StringCol = "value"
select x

When it runs it retrns a runtime error about casting to an integer. I found a nice post about the issue and the solution at http://jason.pettys.name/archive/2009/09/28/nhibernate-with-linq-error-with-string-comparisons-in-vb.net.aspx

But my question is what is a "visitor" and what code would I write to achive the solution highlighted in the above post - missing the link here !!!

+1  A: 

Visitor is a design pattern. You can find a description of it here http://www.dofactory.com/Patterns/PatternVisitor.aspx or here http://en.wikipedia.org/wiki/Visitor_pattern

If I correctly understand the article you linked to (haven't read it fully), then it is required to change NHibernate to work around this problem.

M4N
Martin is correct -- you do have to modify the NHibernate.Linq source. The ExpressionVisitor is the name of the class in the NHibernate.Linq library you have to modify.Grab the NHibernate.Linq source for v1.0.0.4000 and modify NHibernate.Linq.Visitors.ExpressionVisitor, insert the code below as the very first line of the VisitBinary method: b = FixVbStringComparison(b);Also include the implementation of FixVbStringComparision from the blog post.Sorry I didn't post a DLL with the blog post -- there are non-technical involved with that for me.
pettys
A: 

The definition of the visitor pattern is: "Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates."

The namespace of the visitor(s) you want to change is NHibernate.Linq.Visitors. You will probably have more difficulties using VB instead of C# with NHibernate.Linq, because VB3 does not support everything c#3 does. Those problems will be solved if you use .Net 4.0 (or c# of course)

Paco