为什么我从C#到VB的转换不起作用?

时间:2010-02-23 13:31:45

标签: c# vb.net

原始代码:

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>();
}

我转换的代码:

  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

我在使用VB版本的Visual Studio中出错:

错误1扩展方法'Public Function ToList()As System.Linq.Enumerable'中定义的System.Collections.Generic.List(Of TSource)'不是通用的(或者没有自由类型参数),所以不能有类型参数。

错误在Return语句中,而Contact用蓝色波浪线加下划线。

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

将其更改为:

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