1

I had the following c# code:

public T Single(Expression<Func<T, bool>> where)
    {
        return _dbset.Single<T>(where);
    }

I tried to convert this to vb.net using a conversion tool which rendered the code as follows:

Public Function [Single](where As Expression(Of Func(Of T, Boolean))) As T
    Return _dbset.[Single](Of T)(where)
End Function

This is throwing an error "Overload resolution failed because no accessible 'Single' accepts this number of arguments

Any idea of how to correct this?

4

2 回答 2

1

The compiler isn't able to bind to the right static method for some reason - possibly because it doesn't know if you want Enumerable.Single or Queryable.Single. You can get around it by calling the extension method statically:

Public Function [Single](where As Expression(Of Func(Of T, Boolean))) As T
    Return Queryable.Single(Of T)(_dbset, where)
End Function
于 2014-12-11T17:45:43.737 回答
1

我不记得我头脑中的原因,但在这些情况下,它通常只需将泛型说明符完全放在方法调用上即可:

Public Function Single(ByVal where As Expression(Of Func(Of T, Boolean))) As T
        Return _dbset.Single(where)
End Function
于 2014-12-11T20:05:15.387 回答