tags:

views:

93

answers:

2

The original code:

public List<Contact> GetContactListEntityCompiledLINQ()
{
    if (entities == null) entities = new CompanyEntities();

    ObjectQuery<Contact> contacts = compiledQuery.Invoke(entities);
    if (NoTracking) contacts.MergeOption = MergeOption.NoTracking;

    return contacts.ToList<Contact>();
}

My converted code:

  Public Function GetContactListEntityCompiledLINQ() As List(Of Contact)

        If entities Is Nothing Then entities = New CompanyEntities()

        Dim contacts As ObjectQuery(Of Contact) = compiledQuery.Invoke(entities)
        If NoTracking Then contacts.MergeOption = MergeOption.NoTracking

        Return contacts.ToList(Of Contact)()

    End Function

I get an error in Visual Studio with the VB version:

Error 1 Extension method 'Public Function ToList() As System.Collections.Generic.List(Of TSource)' defined in 'System.Linq.Enumerable' is not generic (or has no free type parameters) and so cannot have type arguments.

The error is on the Return statement, and Contact is underlined with the blue squiggly.

Any ideas?

+3  A: 

Change it to this:

Public Function GetContactListEntityCompiledLINQ() As List(Of Contact)

    If entities Is Nothing Then entities = New CompanyEntities()

    Dim contacts As ObjectQuery(Of Contact) = compiledQuery.Invoke(entities)
    If NoTracking Then contacts.MergeOption = MergeOption.NoTracking

    Return contacts.ToList()

End Function
Andrew Hare
It should return the generic version though, shouldn't it? Or it's not a true translation...
SLC
It'll still return a generic list. The type parameter is implied.
SLaks
The original code should have worked as far as I can tell but what I have posted will work and is identical at the IL level.
Andrew Hare
Fair enough then! Thanks for your help :)
SLC
A: 

you can use this:

http://www.developerfusion.com/tools/convert/csharp-to-vb/

Tyzak