Or in Where Clause causing failure

Posts   
 
    
GabeNodland avatar
Posts: 65
Joined: 31-Dec-2004
# Posted on: 06-Sep-2008 00:27:54   

I found something that seems strange to me.

the following code:


        Public Shared Function FindPart(ByVal searchString As String) As PartEntity()
            Dim meta As New metadata(New adapter)

            Dim q = From p In meta.Part _
              Where p.PartDescription.Contains(searchString) _
              Or (p.PartNumber.Contains(searchString)) _
              Select p

            q = q.WithPath(New PathEdge(Of MaterialEntity)(PartEntity.PrefetchPathMaterials))

            Return q.ToArray

        End Function

Produces this error:

An exception was caught during the execution of a retrieval query: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name. . Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

However when I change Or to OrElse it works fine. I looked in the documentation and didn't see mention of "Or" not being supported.

Am I doing something wrong? or is OrElse what I should be using?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Sep-2008 07:43:35   

Indeed, apparently the "conditional OR" operator (OrElse in VB and || in C#) is the one that should be used for filter.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 07-Sep-2008 11:50:07   

'Or' suggests a bitwise Or operation (which is otherwise not possible to specify). In Linq expression trees you have Expression.Or and Expression.OrElse. the former is a bitwise or, the latter is the logical or, which you want. simple_smile

The C# compiler produces an Expression.OrElse when it sees a || in the query.

Frans Bouma | Lead developer LLBLGen Pro