Overview
Simple, fast, and straightforward to learn — install the core package, install your provider, call its setup method once, then start calling repository methods.
RepoDB works the same way no matter which database you’re targeting: install the core package, install the provider package for your database, call the provider’s global setup method once at startup, and start calling operations like Insert, Query, Update, and Delete directly off the connection.
Start with Installation for the full package list across every supported RDBMS, or jump straight to your database below for a complete walkthrough — creating a table and model, and running through inserts, queries, merges, deletes, and updates.
Choose your database
| Database | Description |
|---|---|
| ClickHouse | An open-source, column-oriented database built for real-time analytics at scale. |
| DB2 | IBM’s enterprise-grade relational database for mission-critical workloads. |
| EnterpriseDB | A PostgreSQL-based platform with added enterprise features and support. |
| Firebird | A lightweight, open-source relational database with strong SQL standard compliance. |
| MariaDB | A community-driven, open-source fork of MySQL with enhanced performance features. |
| MySQL | One of the world’s most popular open-source relational databases. |
| Oracle | A powerful, enterprise-grade relational database used across large organizations. |
| PostgreSQL | An advanced open-source object-relational database known for reliability and extensibility. |
| SAP HANA | An in-memory, column-oriented database platform built for real-time analytics. |
| SQL Server | Microsoft’s relational database management system for enterprise applications. |
| SQLite | A self-contained, serverless database engine embedded directly in applications. |
| Vertica | A columnar analytics database built for large-scale data warehousing. |
Already have a database picked out? Telemetry is worth a look too — it’s opt-in, drop-in instrumentation for every operation your application makes.
How to Get Started
- Install the core package and the package for your database.
- Call the provider’s global setup method once, at application startup.
- Start calling operations — Insert, Query, Update, Delete, and more — directly off the connection.
The samples below use SQL Server to illustrate the pattern. The API is identical across every provider — swap the connection type and package names for your own database.
Installation
Install the core package and your provider’s package via NuGet using the Package Manager Console.
> Install-Package RepoDb
> Install-Package RepoDb.SqlServer
Then call the provider’s global setup method once at startup.
GlobalConfiguration
.Setup()
.UseSqlServer();
See Installation for the full package list across every supported RDBMS.
Sample CRUD
public class Person
{
public long Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public DateTime CreatedDateUtc { get; set; }
}
Insert a row via Insert.
using (var connection = new SqlConnection(ConnectionString))
{
var id = connection.Insert(new Person
{
Name = "John Doe",
Age = 54,
CreatedDateUtc = DateTime.UtcNow
});
}
Query a row via Query.
using (var connection = new SqlConnection(ConnectionString))
{
var person = connection.Query<Person>(e => e.Id == 10045).FirstOrDefault();
}
Update a row via Update.
using (var connection = new SqlConnection(ConnectionString))
{
var updatedRows = connection.Update(new Person
{
Id = 10045,
Name = "James Doe",
Age = 55,
CreatedDateUtc = DateTime.UtcNow
});
}
Delete a row via Delete.
using (var connection = new SqlConnection(ConnectionString))
{
var deletedRows = connection.Delete<Person>(10045);
}
See the full walkthrough — including querying all rows, merging, and dynamic updates — on your database’s quickstart page.
Sample Batch CRUD
InsertAll, MergeAll, UpdateAll and DeleteAll batch multiple statements into a single round-trip. Adjust how many rows are packed per round-trip via the batchSize argument (defaults to 10).
using (var connection = new SqlConnection(ConnectionString))
{
var people = GetPeople(1000);
var insertedRows = connection.InsertAll(people, batchSize: 100);
}
using (var connection = new SqlConnection(ConnectionString))
{
var people = GetPeople(1000).AsList();
people.ForEach(p => p.Name = $"{p.Name} (Updated)");
var updatedRows = connection.UpdateAll(people, batchSize: 100);
}
using (var connection = new SqlConnection(ConnectionString))
{
var primaryKeys = new[] { 10045, 11001, 12011 };
var deletedRows = connection.DeleteAll<Person>(primaryKeys);
}
Sample Bulk CRUD
For 1,000 rows or more, prefer the true bulk operations. They require a provider’s dedicated .BulkOperations package installed alongside the core provider.
> Install-Package RepoDb.SqlServer.BulkOperations
using (var connection = new SqlConnection(ConnectionString))
{
var people = GetPeople(10000);
var insertedRows = connection.BulkInsert(people);
}
using (var connection = new SqlConnection(ConnectionString))
{
var people = GetPeople(10000).AsList();
people.ForEach(p => p.Name = $"{p.Name} (Merged)");
var mergedRows = connection.BulkMerge(people);
}
using (var connection = new SqlConnection(ConnectionString))
{
var inactivePeople = connection.Query<Person>(e => e.Age > 90).AsList();
var deletedRows = connection.BulkDelete(inactivePeople);
}
See BulkInsert, BulkMerge, BulkUpdate, BulkDelete and BulkDeleteByKey for the full reference — every database provider ships the same five methods under its own operation group.
Sample RAW SQL Executions
Run a non-query statement via ExecuteNonQuery.
using (var connection = new SqlConnection(ConnectionString))
{
var affectedRecords = connection.ExecuteNonQuery(
"DELETE FROM [dbo].[Person] WHERE Id = @Id;", new { Id = 1 });
}
Run a query and map the results via ExecuteQuery.
using (var connection = new SqlConnection(ConnectionString))
{
var people = connection.ExecuteQuery<Person>(
"SELECT * FROM [dbo].[Person] ORDER BY Id ASC;");
}
Run a query and return a single scalar value via ExecuteScalar.
using (var connection = new SqlConnection(ConnectionString))
{
var maxId = connection.ExecuteScalar<long>("SELECT MAX(Id) FROM [dbo].[Person];");
}
Sample Telemetry
RepoDB ships opt-in, drop-in telemetry via RepoDb.Telemetry.Default — install it, wire it up once, and every operation across every connection gets traced automatically.
> Install-Package RepoDb.Telemetry.Default
var telemetryOption = new DefaultTelemetryOption("<YOUR_APPLICATION_NAME>")
{
Host = "https://your-collector-host",
ApiKey = "YOUR_API_KEY",
Group = "<YOUR_APPLICATION_GROUP>"
};
GlobalConfiguration
.Setup(new GlobalConfigurationOptions { UseRegisteredGlobalTraces = true })
.UseDefaultTelemetry(telemetryOption);
See Telemetry for the full setup guide, including running the collector via Docker.