C# Dapper - Npgsql
Overview
Dapper is a simple object-relational mapper (ORM) for .NET. It provides an easy and efficient way to query databases with minimal setup and overhead, leveraging SQL directly while mapping results to C# objects. This page describes how to use Dapper with Npgsql (a PostgreSQL data provider for .NET) to connect to Oxla.
Establishing connection
There are two ways that can be utilised in order to establish a connection through Npgsql:
- Npgsql’s DataSource Class
- Creating Connection Directly
For more details on connection string options, including SSL configuration, please refer to Npgsql docs.
Example Usage
This example shows basic query execution for the following C# class, once the connection has been established:
INSERT INTO Customer VALUES (@ClientId, @Height, @FirstName)
syntax uses prepared statements under the hood, which are not supported by Oxla. We translate incoming binary input back into string, thus no benefits of such statements apply (no security or performance improvements)Unsupported Functions & Structures
Here you can find a list of functions and potentially related structures, that we either do not support at all or they work incorrectly when combining Oxla and Dapper-Npgsql:
connection.Execute
- returns improper number of rows forDELETE
,UPDATE
,INSERT INTO ... (SELECT)
andCOPY
statementsconnection.BeginTransaction
- TransactionsCommandType.StoredProcedure
- Stored Procedures- Function in/out parameters