NibblyPig
NibblyPig

Reputation: 52922

Why doesn't my conversion from C# to VB work?

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?

Upvotes: 3

Views: 1022

Answers (1)

Andrew Hare
Andrew Hare

Reputation: 351456

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

Upvotes: 6

Related Questions