Question : Convert LINQ in C# to VB.NET

Hi all,

I am converting some code from C# to VB.NET but I'm having some trouble with LINQ.

The following is a line a code I wish to convert:
var page = db.Pages.Single(p => p.ID == NewPageId);

After converting I get the following line:
Dim page = db.Pages.[Single](Of Page)(Function(p) p.ID = NewPageId)

Whe I do this I get the following error:
Overload resolution failed because no accessible 'Single' accepts this number of type arguments.

Any help is greatly appreciated!

Thank you.

Answer : Convert LINQ in C# to VB.NET

System.Linq is not an assembly, it's a namespace. System.Data.Linq would be an assembly, but it may not be needed. Can you try to compile the following code snippet in a vb class file in the same project? If the references are set fine, it should compile fine.

Note that your code should work equally well as follows:

Dim page As Page = db.Pages.Single(Function(p) p.ID = NewPageId)
1:
2:
3:
4:
5:
6:
Public Class Class1
    Public Sub New()
        Dim test As New List(Of Integer)
        test.Single(Function(i) i = 1)
    End Sub
End Class
Random Solutions  
 
programming4us programming4us