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
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.
1 Comment
Simply it is not possible, but I would suggest Gridify, it is a fast and easy-to-use dynamic linq library.