tags:

views:

267

answers:

2

I'm triying to do exactly the same thing described here, but in VB.NET

I tried all of the C# to VB converters but no one seems to work with LINQ. I'm totaly new to C#, so any help will be appreciated !

public static IQueryable<Type> HasID(this IQueryable<Type> query, long? id) { return id.HasValue ? query.Where(o => i.ID.Equals(id.Value)) : query; }

+2  A: 

Try this:

Public Module MyModule
    <Runtime.CompilerServices.Extension()> _
    Public Function HasID(ByVal query As IQueryable(Of Type), ByVal id As Long?) As IQueryable(Of Type)
        Return If(id.HasValue, query.Where(Function(o) o.ID.Equals(id.Value)), query)
    End Function
End Module

In VB.NET you should create a module to create an extension method. Also place the Runtime.CompilerServices.Extension attribute and remove static and this from function definition.

P.S. hate VB:)

Kamarey
Tell what is "Type" type?
Kamarey
A: 

Which converter have you tried? You should try Telerik Converter. I have copied your code into their converter and got this:

<System.Runtime.CompilerServices.Extension> _
Public Shared Function HasID(query As IQueryable(Of Type), id As System.Nullable(Of Long)) As IQueryable(Of Type)
    Return If(id.HasValue, query.Where(Function(o As ) i.ID.Equals(id.Value)), query)
End Function



'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Built and maintained by Todd Anglin and Telerik
'=======================================================
M. Jahedbozorgan
The firsts in Google. Yeah not "all" in fact. Thanks I have bookmarked this one !
+1 for mentioning the source.