I was looking for an answer to this question too... surprised it is so
difficult to find information. In case you don't know, this is
possible using CreateCriteria:
http://stackoverflow.com/questions/1436085/nhibernate-convert-guid-to-string-in-query/1436762#1436762

On Sep 24, 5:59 am, roend <[email protected]> wrote:
> Hi,
>
> I'm having a problem trying to get NHibernate.Linq to generate a
> 'like' query on an integer column.  The SQL that I'd like it to
> produce is:
>
> select IntegerColumn
> from Table
> where IntegerColumn like '%StringValue%'
>
> I've tried using the following code:
>
> from entity in _session.Linq<Entity>
> where entity.IntegerColumn.ToString().Contains(StringValue)
> select entiry.IntegerColumn
>
> This code throws an ArgumentOutOfRangeException.  See the stack trace
> below.
>
> Is there any way that I can do this using a Linq expression?
>
> Thanks,
> Nathan
>
> STACK TRACE:
>    at System.ThrowHelper.ThrowArgumentOutOfRangeException
> (ExceptionArgument argument, ExceptionResource resource)
>    at System.ThrowHelper.ThrowArgumentOutOfRangeException()
>    at System.SZArrayHelper.get_Item[T](Int32 index)
>    at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item
> (Int32 index)
>    at NHibernate.Linq.Visitors.MemberNameVisitor.VisitMethodCall
> (MethodCallExpression expr)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit
> (Expression exp)
>    at NHibernate.Linq.Visitors.MemberNameVisitor.GetMemberName
> (ICriteria rootCriteria, Expression expr)
>    at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetLikeCriteria
> (MethodCallExpression expr, MatchMode matchMode)
>    at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitMethodCall
> (MethodCallExpression expr)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit
> (Expression exp)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.VisitLambda
> (LambdaExpression lambda)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit
> (Expression exp)
>    at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitUnary
> (UnaryExpression expr)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit
> (Expression exp)
>    at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCriterion
> (ICriteria rootCriteria, ISession session, Expression expression)
>    at NHibernate.Linq.Visitors.RootVisitor.HandleWhereCall
> (MethodCallExpression call)
>    at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall
> (MethodCallExpression expr)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit
> (Expression exp)
>    at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall
> (MethodCallExpression expr)
>    at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit
> (Expression exp)
>    at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate
> (Expression expression, QueryOptions queryOptions)
>    at NHibernate.Linq.NHibernateQueryProvider.TranslateExpression
> (Expression expression)
>    at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression
> expression)
>    at NHibernate.Linq.Query`1.GetEnumerator()
>    at System.Collections.Generic.List`1..ctor(IEnumerable`1
> collection)
>    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
>    at MyApplication.Controller.MyMethod(String q, Int32 limit) in c:
> \MyFile\Controller.cs:line 30
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to