Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData SingleResult is Ambiguous in System.Web.Http

I am new to using OData with a Web Api. I have my models defined from a database first EF 6 method, and have added the OData controller. The resulting code is erroring out on the following:

< EnableQuery > _

    Public Function [Get](<FromODataUri> key As Integer) As SingleResult(Of Product)
        Dim result As IQueryable(Of Product) = db.Product.Where(Function(p) p.ID= key)
        Return SingleResult.Create(result)
    End Function

The error is on the SingleResult providing the following error: SingleResult is ambiguous in system.web.http.

Any advice on what causes this error? Many thanks!

like image 479
user3812699 Avatar asked Nov 16 '25 20:11

user3812699


2 Answers

Make sure you don't have multiple OData NuGets installed. I had 2.1 and 2.2 (for OData v4 support) installed, which gave me the exact same issue.

like image 160
drewsky7821 Avatar answered Nov 18 '25 18:11

drewsky7821


Try this:

Return SingleResult(of Product).Create(result)
like image 32
Tan Jinfu Avatar answered Nov 18 '25 19:11

Tan Jinfu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!