Dapper.OData 2.0.0

dotnet add package Dapper.OData --version 2.0.0
NuGet\Install-Package Dapper.OData -Version 2.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="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dapper.OData --version 2.0.0
#r "nuget: Dapper.OData, 2.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=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

MIT

New in this Release

Added Support for Oracle Database with some new mwthods for multi query result.

Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 903 7/1/2021
1.0.0 471 12/3/2020