Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this library be used to generate the request url only? #99

Closed
dradovic opened this issue Apr 10, 2015 · 14 comments
Closed

Can this library be used to generate the request url only? #99

dradovic opened this issue Apr 10, 2015 · 14 comments

Comments

@dradovic
Copy link

I was looking for a library that could translate a C# filter expression into a proper OData query string. Simple.OData.Client certainly needs to do this internally. My question is: is this functionality somehow exposed? Can I use it to get an OData request URL without actually fetching the objects?

@object
Copy link
Member

object commented Apr 10, 2015

Sure, that's possible. Here is an example:

        var command = _client
            .For<Product>()
            .Filter(x => x.ProductID == 1L);
        string commandText = await command.GetCommandTextAsync();
        Assert.Equal("Products(1L)", commandText);

@dradovic
Copy link
Author

Thanks. It seems like GetCommandTextAsync is actually already firing a request. I was more looking for something that can be called "offline". Does that make sense?

@object
Copy link
Member

object commented Apr 11, 2015

No, it doesn't fire the request for the given command, but it needs to make a single request to fetch metadata document. For simple queries it's possible to generate the URI without knowing metadata, but in general case knowing service metadata is necessary. I can think of the way of providing metadata as a local file, so the client doesn't need to make a network roundtrip.

@object
Copy link
Member

object commented Apr 11, 2015

The version 4.4 (coming in a day or two) will have ODataClientSettings.MetadataDocument property that you can use to initialize with the service metadata. Then it will not make an extra call to retrieve a metadata document while executing GetCommandTextAsync.

@dradovic
Copy link
Author

I see. Thank you very much for your time and your wonderful library.

@object
Copy link
Member

object commented Apr 12, 2015

And the version 4.4 is out with support for MetadataDocument in ODataClientSettings.

@object object closed this as completed Apr 12, 2015
@rekosko
Copy link

rekosko commented Apr 23, 2020

But still, can't we just use it with simple:

Expression<Func<T,bool>> expression = ...
var string = expression.GiveMeThatODataString(); // ?

I also need a way to translate my linq expression to odata string and nothing else.
Is it possible somehow with this library?

@watfordgnf
Copy link
Member

@rekosko you're specifically looking for the translation of a filter expression? In any case the expression it generates would be based on the entities involved. You could remove the base URL from the generated command text.

@cbfrank
Copy link

cbfrank commented May 7, 2020

I have the same requirement as rekosko, I would like to just translate an Expression<Func<T,bool>> to a odata query string. but before the demo code can work, I need to create an ODataClient with a valid url that host an odata api, if I specify an url like "127.0.0.1", the GetCommandTextAsync will throw HttpRequestException. can we split the GetCommandTextAsync as an mini tool function?

@watfordgnf
Copy link
Member

@cbfrank to generate it, it needs the metadata for the service. Would your client have the metadata locally?

@cbfrank
Copy link

cbfrank commented May 7, 2020

@watfordgnf sorry, no it doesn't have. actually, the web api is not an odata standard api, it just have a "Get" method which support query string of odata format. this is why I can't provide any url when creating ODataClient.

@watfordgnf
Copy link
Member

Without metadata we cannot properly generate the OData expression.

@cbfrank
Copy link

cbfrank commented May 7, 2020

@watfordgnf I see. Maybe I can try to create a metadata manually, and then use the GetCommandTextAsync . Is this a possible solution?

@watfordgnf
Copy link
Member

If GetCommandTextAsync() does not use a local metadata document you can open a bug and we'll get a fix in for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants