views:

121

answers:

4

VB.NET equivalent to this C# code?

    ctx.Load(site,
                x => x.Lists.Where(l => l.Title != null));

I've tried

 ctx.Load(site, Function(x) x.Lists.Where(Function(l) l.Title IsNot Nothing))

but this errors with "The expression (Convert(l.Title) != null) is not supported."

Thoughts

+2  A: 

if Title is string try use IsNullOrEmpty();

or

Nullable(Of T).HasValue if Title is Nullable

or

Sub Main()

        Dim list As New List(Of A)

        Dim a1 As New A
        a1.Title = "sqws"
        Dim a2 As New A
        a2.Title = Nothing


        list.Add(a1)
        list.Add(a2)

        Dim q = From c In list Where c.Title IsNot Nothing

    End Sub



    Public Class A

        Dim t As String

        Public Property Title() As String
            Get
                Title = t
            End Get
            Set(ByVal value As String)
                t = value
            End Set
        End Property

    End Class
igor
I've tried these and 1) type is not nullable its a String. 2) cannot seem to do string comparisons in the lambda statement...
Bob
see my sample, please. it works
igor
A: 

Have you tried the IsNothing function?

ctx.Load(site, Function(x) x.Lists.Where(Function(l) Not IsNothing(l.Title)))

EDIT:

Now that you've specified that Title is a String, then you should use the IsNullOrEmpty function.

ctx.Load(site, Function(x) x.Lists.Where(Function(l) Not String.IsNullOrEmpty(l.Title)))
Aaron Daniels
when I try this in the Lambda expression I receive an error stating that the IsNnothing member cannot be used in the expression...
Bob
A: 

This really should work:

ctx.Load(site, Function(x) x.Lists.Where(Function(l) l.Title.IsNullOrEmpty = False))

If it does not, let me know the error message.

Patrick Karcher
+2  A: 

This may be cheating, but I have used Reflector in the past to decompile my C# code and then display it as other .NET languages just to see how they would look as I am most fluent in C#

Rob Goodwin