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?

MikeSW
  • 16,140
  • 3
  • 39
  • 53
Jay
  • 3,012
  • 14
  • 48
  • 99

2 Answers2

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
D Stanley
  • 149,601
  • 11
  • 178
  • 240
  • Cheers will give it a go when i get back on dev machine, syntax is killing me in vb.net need more practice lol – Jay Dec 11 '14 at 18:52
1

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
Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28