[英]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: 我在Visual Studio中使用VB版本出错:
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. 错误1扩展方法'Public Function ToList()As System.Linq.Enumerable'中定义的System.Collections.Generic.List(Of TSource)'不是通用的(或没有自由类型参数),因此不能有类型参数。
The error is on the Return statement, and Contact is underlined with the blue squiggly. 错误发生在Return语句中,Contact用蓝色波浪形加下划线。
Any ideas? 有任何想法吗?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.