odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

The method 'Any' is not supported

Open ShvetsovAU opened this issue 4 years ago • 8 comments

Hello. I am using Microsoft.OData.Client 7.8.1.

I want create DataServiceContext, CreateQuery and take data.

Code is:

var oDataContext = new DataServiceContext(new Uri("https://localhost:5001"));
var dataSet = oDataContext.CreateQuery<Project>("Projects");
var exists = dataSet.Any();

But i get next error: "System.NotSupportedException: 'The method 'Any' is not supported.'"

StackTrace:

at Microsoft.OData.Client.DataServiceQueryProvider.ReturnSingleton[TElement](Expression expression) at Microsoft.OData.Client.DataServiceQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.Any[TSource](IQueryable`1 source) at ASE.MD.MDP2.Product.MDP2Service.Controllers.TestController.GetByOData() in D:\WorkProjects\MDP\2.0\MDP2.0\MDP2Service\Controllers\TestController.cs:line 146 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext()

What's wrong i do?

ShvetsovAU avatar Feb 08 '21 09:02 ShvetsovAU

@ShvetsovAU this is a great suggestion. It might be a good opportunity if you want to make a contribution. We'll be happy to review.

ElizabethOkerio avatar Feb 09 '21 17:02 ElizabethOkerio

The error method is thrown from 'https://github.com/OData/odata.net/blob/master/src/Microsoft.OData.Client/ALinq/DataServiceQueryProvider.cs#L142'

xuzhg avatar Feb 09 '21 17:02 xuzhg

@ShvetsovAU this is a great suggestion. It might be a good opportunity if you want to make a contribution. We'll be happy to review.

Which methods of linq is not supported now?

ShvetsovAU avatar Feb 09 '21 18:02 ShvetsovAU

Maybe you can recomended another library for translating linq to OData queries?

ShvetsovAU avatar Feb 10 '21 03:02 ShvetsovAU

@ShvetsovAU most of the linq methods are supported by OData Client.. check out this doc https://docs.microsoft.com/en-us/odata/client/query-options. There are also aggregation methods that have recently been supported. https://github.com/OData/odata.net/pull/1921

ElizabethOkerio avatar Feb 12 '21 05:02 ElizabethOkerio

@ShvetsovAU most of the linq methods are supported by OData Client.. check out this doc https://docs.microsoft.com/en-us/odata/client/query-options. There are also aggregation methods that have recently been supported. #1921

Hello, thank you!

But as i can see, not supported next methods (which i try using): All, Last, LastOrDefault, Contains, Any...another don not try use...

ShvetsovAU avatar Feb 12 '21 06:02 ShvetsovAU

hi team, any update on this ? I encounter the same issue

qcnguyen avatar Nov 07 '21 03:11 qcnguyen

2024 and Any still not supported? I'm confused because this page in the documentation shows examples with Any. Are there any plans to support it? Or maybe it's supported but I'm not using the right library? Please somebody bring some light to my questions, as I don't understand anything!

joecarl avatar Feb 16 '24 15:02 joecarl