我想将我的一些 EntityFramework C# 代码移植到 VB.NET 中。我正在尝试不同的在线代码转换器,但他们无法为我解决这个问题。
我有这两个功能。
public List<T> Find<T>(Func<T, bool> predicate) where T : class
{
var objectSet = db.CreateObjectSet<T>();
return objectSet.Where<T>(predicate).ToList();
}
public void Delete<T>(Func<T, bool> predicate) where T : class
{
var objectSet = db.CreateObjectSet<T>();
IEnumerable<T> records = from x in objectSet.Where<T>(predicate) select x;
foreach (T record in records)
{
objectSet.DeleteObject(record);
}
}
现在转换器告诉我:
Public Function Find(Of T As Class)(predicate As Func(Of T, Boolean)) As List(Of T)
Dim objectSet = db.CreateObjectSet(Of T)()
Return objectSet.Where(Of T)(predicate).ToList()
End Function
Public Sub Delete(Of T As Class)(predicate As Func(Of T, Boolean))
Dim objectSet = db.CreateObjectSet(Of T)()
Dim records As IEnumerable(Of T) = From x In objectSet.Where(Of T)(predicate) Select x
For Each record As T In records
objectSet.DeleteObject(record)
Next
End Sub
但我得到两个错误,两者objectSet.Where<T>(predicate)
都是:
重载解析失败,因为没有可访问的“Where”接受此数量的类型参数。