Sreeni.OData.Transpiler.Azure.Cosmos
1.0.2
dotnet add package Sreeni.OData.Transpiler.Azure.Cosmos --version 1.0.2
NuGet\Install-Package Sreeni.OData.Transpiler.Azure.Cosmos -Version 1.0.2
<PackageReference Include="Sreeni.OData.Transpiler.Azure.Cosmos" Version="1.0.2" />
paket add Sreeni.OData.Transpiler.Azure.Cosmos --version 1.0.2
#r "nuget: Sreeni.OData.Transpiler.Azure.Cosmos, 1.0.2"
// Install Sreeni.OData.Transpiler.Azure.Cosmos as a Cake Addin #addin nuget:?package=Sreeni.OData.Transpiler.Azure.Cosmos&version=1.0.2 // Install Sreeni.OData.Transpiler.Azure.Cosmos as a Cake Tool #tool nuget:?package=Sreeni.OData.Transpiler.Azure.Cosmos&version=1.0.2
Sreeni.OData.Transpiler.Azure.Cosmos
Sreeni.OData.Transpiler.Azure.Cosmos is a .NET-based OData query translator specifically designed for Azure Cosmos DB.
It translates OData queries into Cosmos DB SQL queries, enabling seamless integration and query translation for Azure Cosmos DB.
Features
- Parse OData queries
- Convert OData queries to Cosmos DB SQL queries
- Support for common OData query options:
$select
,$filter
,$orderby
,$top
,$skip
, and$expand
- Support for nested fields in the select clause, filter expressions, and orderby expressions
- Execute translated queries against Azure Cosmos DB
Getting Started
Installation
To install the package, add the following dependency to your project:
dotnet add package Sreeni.OData.Transpiler.Azure.Cosmos
Usage
This package provides the necessary components to translate and execute OData queries against Azure Cosmos DB. The following steps outline how to use the package:
- Create an instance of
ODataAzureCosmosClient
:- You can create an instance using either a
CosmosClient
object or a connection string.
- You can create an instance using either a
using Microsoft.Azure.Cosmos;
using Sreeni.OData.Transpiler.Azure.Cosmos;
// Using CosmosClient object
var cosmosClient = new CosmosClient("your-cosmos-db-connection-string");
var client = new ODataAzureCosmosClient(cosmosClient, "your-database-name", "your-container-name");
// Using connection string
var client = new ODataAzureCosmosClient("your-cosmos-db-connection-string", "your-database-name", "your-container-name");
- Execute OData queries:
- Use the
GetItemByQueryAsync
method to execute a query and get a single item. - Use the
GetListByQueryAsync
method to execute a query and get a list of items.
- Use the
// Example OData query
string odataQuery = "$select=Name,Age&$filter=Age gt 30&$orderby=Name&$top=10&$skip=5";
// Get a single item
var item = await client.GetItemByQueryAsync(odataQuery);
// Get a list of items
var items = await client.GetListByQueryAsync(odataQuery);
Implementation Details
The ODataAzureCosmosClient
class uses the ODataAzureCosmosQueryTranslator
to translate OData queries into Cosmos DB SQL queries. The translation process involves the following steps:
Parse the OData query:
- The
ODataQueryParser
class parses the OData query string into anODataQuery
object.
- The
Translate the OData query:
- The
ODataAzureCosmosQueryTranslator
class translates theODataQuery
object into a Cosmos DB SQL query using various query visitors (SelectVisitor
,FilterVisitor
,OrderByVisitor
,TopVisitor
,SkipVisitor
,ExpandVisitor
).
- The
Execute the translated query:
- The
ODataAzureCosmosClient
class executes the translated query using the Azure Cosmos DB SDK.
- The
Example
Here is a complete example of how to use the Sreeni.OData.Transpiler.Azure.Cosmos
package:
using Microsoft.Azure.Cosmos;
using Sreeni.OData.Transpiler.Azure.Cosmos;
using System; using System.Threading.Tasks;
public class Program
{
public static async Task Main(string[] args)
{
var cosmosClient = new CosmosClient("your-cosmos-db-connection-string");
var client = new ODataAzureCosmosClient(cosmosClient, "your-database-name", "your-container-name");
string odataQuery = "$select=Name,Age&$filter=Age gt 30&$orderby=Name&$top=10&$skip=5";
var items = await client.GetListByQueryAsync<YourEntityType>(odataQuery);
foreach (var item in items)
{
Console.WriteLine(item);
}
}
}
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.Azure.Cosmos (>= 3.46.0)
- Sreeni.OData.Transpiler.Core (>= 1.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.