Dapper.OData
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Dapper.OData --version 1.0.0
NuGet\Install-Package Dapper.OData -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dapper.OData" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dapper.OData --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Dapper.OData, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Dapper.OData as a Cake Addin #addin nuget:?package=Dapper.OData&version=1.0.0 // Install Dapper.OData as a Cake Tool #tool nuget:?package=Dapper.OData&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Usage
In Startup.cs
using Dapper.OData;
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
...
services.AddRouting();
services.AddDapperOData(GetEdmModel(), Configuration.GetConnectionString("DefaultConnection")); //Add this line
}
Creating EDM Model
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
...
builder.EntitySet<Order>(nameof(Order) + "s").EntityType.HasKey(x => x.Order_Id);
...
var edmModel = builder.GetEdmModel();
return edmModel;
}
In a Sample Controller
using Dapper.OData.Infrastructure;
using Dapper.OData.Models;
public class OrdersController : ControllerBase
{
private readonly IDbConnection _db;
public OrdersController(IDbConnection db)
{
_db = db;
}
[EnableQuery]
public IQueryable<Order> GetOrders(DbParams dbParams)
{
var query = "{your query}";
var orders = _db.GetQueryableResult<Order>(query, out _, filter: dbParams.Filter, top: dbParams.Top, skip: dbParams.Skip, take: dbParams.Take, orderBy: dbParams.OrderBy);
return orders;
}
}
Query Data
You can use OData query options ($select, $filter, $count, $top, $skip, $orderby) as well as you can take query result directly from the database by using custom paramters as filter, top, skip, take, orderBy.
Operator Grammer
These Operators will be used to add filter for the database
Operator | Description |
---|---|
NOT | Not Operator |
EQ | Equals Operator |
NE | Not Equals Operator |
GT | Greater Than |
LT | Less Than |
GE | Greater Than and Equals To |
LE | Less Than and Equals To |
BTW | Between |
LK | Like |
AND | And Operator |
OR | Or Operator |
IN(...) | In Operator |
'string' | Any string will be placed in single qoutes |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- Dapper (>= 2.0.78)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.OData (>= 8.0.0-preview2)
- Microsoft.Extensions.DependencyInjection (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- System.Data.SqlClient (>= 4.8.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.