0

I have a console application where I need to store some queries as strings. I'd like to use the OData language to query an object model that I have stored in memory, to avoid reinventing any wheels. Every example I've been able to find so far is for OData queries over the web, and not for just using the OData libraries against local data. Is there a library somewhere available that will support local use?

2 Answers 2

2

The most popular OData implementation for .NET is Microsoft.AspNetCore.OData. You could certainly run this as a "localhost" service, without having to serve it over the web.

They've just a couple of months ago (July 2021) released version 8, which is a from-the-ground-up rewrite, so a lot of the samples/examples/tutorials you might find might not work any more. But they have several very good sample projects in their new repo:

https://github.com/OData/AspNetCoreOData/tree/master/sample

I think as far as using OData, a localhost service would be your best bet. Anything that's not a RESTful service would actually be breaking the OData spec, which begins by saying:

The OData Protocol is an application-level protocol for interacting with data via RESTful interfaces.

(That's probably why you haven't found any examples of OData that aren't "web" based, at least using the term web based to denote that it's running as a RESTful service.)

*Edit: Alternative solution

If you're open to using something more SQL based rather than OData, and assuming you're planning to use something like Entity Framework for your data layer, you can write your where clauses and such in plain text if you use System.Linq.Dynamic.Core. These could easily be stored in strings or text files. That might be quite a bit easier than trying to use OData.

There is also a way to write the entire SQL query in text if you prefer.

Neither of these alternatives would be without risk if security is at all a concern, since they would be subject to injection attacks.

Sign up to request clarification or add additional context in comments.

1 Comment

Injection may not be a problem - I can see how some of the queries are part of the configuration. That said, using dynamic LINQ is the solution I would try - odata is definitely too complex for this.
0

Simply it is not possible, but I would suggest Gridify, it is a fast and easy-to-use dynamic linq library.

https://github.com/alirezanet/Gridify

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.