Why is my conversion from C # to VB not working?

Source:

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 VB version:

Error 1 Extension method 'Public function ToList () Since System.Collections.Generic.List (Of TSource)', defined in 'System.Linq.Enumerable', is not common (or has no parameters of a free type), and therefore cannot be type arguments.

The error is in the Return statement, and Contact is underlined in blue.

Any ideas?

+3
source share
1 answer

Change it like 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
+6
source

Source: https://habr.com/ru/post/1734062/


All Articles