Dapper.OData
2.0.0
dotnet add package Dapper.OData --version 2.0.0
NuGet\Install-Package Dapper.OData -Version 2.0.0
<PackageReference Include="Dapper.OData" Version="2.0.0" />
paket add Dapper.OData --version 2.0.0
#r "nuget: Dapper.OData, 2.0.0"
// Install Dapper.OData as a Cake Addin #addin nuget:?package=Dapper.OData&version=2.0.0 // Install Dapper.OData as a Cake Tool #tool nuget:?package=Dapper.OData&version=2.0.0
Dapper.OData
Enables OData support for a .Net 5 WEBAPI using dapper.
Installation
Use the package manager to install Dapper.OData.
Install-Package Dapper.OData -Version 1.0.0
Use the .Net CLI to install Dapper.OData.
dotnet add package Dapper.OData --version 1.0.0
Use the Package Reference to install Dapper.OData.
<PackageReference Include="Dapper.OData" Version="1.0.0" />
Use the Packet CLI to install Dapper.OData.
paket add Dapper.OData --version 1.0.0
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 |
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
New in this Release
Added Support for Oracle Database with some new mwthods for multi query result.
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. |
-
net5.0
- Dapper (>= 2.0.78)
- Dapper.Oracle (>= 2.0.1)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.OData (>= 8.0.0-preview2)
- Microsoft.Extensions.DependencyInjection (>= 5.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Oracle.ManagedDataAccess.Core (>= 2.19.101)
- 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.