Conversion of repository pattern class from c# to vb.net

448 Views Asked by At

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?

2

There are 2 best solutions below

0
On

I can't remember the reason off the top of my head, but in these cases it often will work by just dropping the generic specifier on the method call altogether:

Public Function Single(ByVal where As Expression(Of Func(Of T, Boolean))) As T
        Return _dbset.Single(where)
End Function
1
On

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