Questions tagged [dapper]

Dapper is a micro-ORM for .NET developed and used by the Stack Overflow team, focusing on raw performance as the primary aim.

Dapper is a micro-ORM, offering core parameterization and materialization services, but (by design) not the full breadth of services that you might expect in a full ORM such as LINQ-to-SQL or Entity Framework. Instead, it focuses on making the materialization as fast as possible, with no overheads from things like identity managers - just "run this query and give me the (typed) data".

However, it retains support for materializing non-trivial data structures, with both horizontal (joined data in a single grid) and vertical (multiple grids) processing.

Quite possibly the fastest materializer available for .NET, and available here: github.com/StackExchange/dapper-dot-net

Getting Started with Dapper

Dapper comprises of a single file: SqlMapper.cs (or SqlMapperAsync.cs for .NET 4.5 if you like async). You can either include the file, as is, in your project. Or install it via nuget.

Here is a video with a simple example.

A simple Hello World sample

using Dapper;
//...
using (var connection = new SqlConnection(myConnectionString))
{
  connection.Open();
  var posts = connection.Query<Post>("select * from Posts");

  //... do stuff with posts
}

CRUD operations

Dapper provides a minimal interface between your database and your application. Even though the interface is minimal it still supports the full array of database operations. Create, Read, Update, Delete are fully supported. Using stored procedures or not.

See also:

The Multi Mapper

Dapper allows you to automatically split a single row to multiple objects. This comes in handy when you need to join tables.

See also:

Performance

A key feature of Dapper is performance. You can go through the performance of SELECT mapping over 500 iterations at this link.

.NET Framework support

Dapper runs best on .NET 4.0 or later. It makes use of Dynamic features in the language and optional params. You can run Dapper on .NET 3.5 as well. There are no known ports that avoid dynamic method generation. There are no known ports to .NET 2.0.

Dapper also works fine in Mono.

Nuget package

Dapper can most easily be installed through its NuGet package.

Install-Package Dapper

Install

Dapper can be used after adding the Reference of of Dapper.dll to the project

Extensions

The Dapper solution includes the following extensions:

  • Dapper.Rainbow
  • Dapper.Contrib
  • Dapper.SqlBuilder

3rd party extensions

There are some extensions available, developed by 3rd parties:

2873 questions
1
vote
1 answer

Insufficient parameters supplied for to the command INSERT in SQLite

I am trying to connect my program to a SQLite DB, I want it to add a row in the DB each time a user logs in, I am using Dapper ORM. I have already checked the names of the databse rows and the User class parameters, I have tried to send both obj and…
Ilya
  • 13
  • 5
1
vote
2 answers

ExecuteAsync Changes Passed Dynamic Parameters Names

I am trying to insert form data to a table using a stored procedure by calling the ExecuteAsync method of Dapper. After sending the parameters names are changed. public static async Task Insert(DynamicParameters dp) { int IsSuccessed; …
1
vote
2 answers

ObservableCollection does not update => DataGrid UI does not show everything

I have a problem with some code i wrote. I am trying to build a Applicant-Administration program. I have a SQL-Server on which is my Database. At the start of the program, a DataGrid is bound to a ObservableCollection which fires a SQL SELECT via…
N0m4n904
  • 123
  • 2
  • 13
1
vote
1 answer

Map with Dapper one table to a nested object

I have a table which has the following columns: | UserId | UserName | SortCode | AccountNumber | And I have the following C# classes public class User { public int UserId { get; set; } public string UserName { get; set; } public…
osotorrio
  • 960
  • 1
  • 11
  • 30
1
vote
0 answers

Dapper giving unhandled exception when trying to insert data to database

I'm writing a C# plugin for Autodesk Navisworks that will iterate through a bunch of 3D elements and write their properties (Category and Family of the element for now) into an Azure database. I'm using Dapper as ORM. When I try to insert the data…
Andrea Tassera
  • 359
  • 3
  • 17
1
vote
2 answers

How to fix DapperExtensions error after I Insert data and get the returned id

I use Dapper-Extentions to pull and push data to database I use unsigned int id as my Primary key in database and in the class as well. my class looks like this public class Product { [Column("id")] public uint Id { get; set; } } My Mapper…
YouneS
  • 390
  • 4
  • 10
1
vote
2 answers

How to ExecuteAsync in Dapper when doing an Oracle INSERT ALL

I have the following SQL command (simplified) assigned to the var sql: INSERT ALL INTO ORACLETBL (COL_A,COL_B) VALUES ('A','B') INTO ORACLETBL (COL_A,COL_B) VALUES ('C','D') SELECT * FROM dual; When I do a conn.Execute(sql); in a void…
k3davis
  • 985
  • 12
  • 29
1
vote
4 answers

How do I read multiple results sets from a PostgreSQL function using Dapper?

I am trying to understand how to use Dapper to make a call to a PostgreSQL function that returns multiple result sets. My understanding is that in PostgreSQL, the best (only?) way to currently achieve this is to declare that the function RETURNS…
dev8675309
  • 356
  • 4
  • 13
1
vote
1 answer

How to Bulk Update column of a table with Entity Framework Core or Dapper?

I need to know what's the best approach to update single column from all rows using EF Core or Dapper. I suppose this is called Bulk Update. I tried EF Plus but I uninstalled after I read about the license trial and I'm looking for a free approach…
Jackal
  • 3,359
  • 4
  • 33
  • 78
1
vote
1 answer

How to get value from procedure with dapper OracleDynamicParameters()?

In my application, I've installed Dapper from nuget package in .net core project. I run a procedure. I see in debug mode that the parameter receives the value, but I can't read this value. public decimal AddMaster(MaterialMaster req) { decimal…
mr. pc_coder
  • 16,412
  • 3
  • 32
  • 54
1
vote
1 answer

Is there an easier way to make this query?

I have two different tables from a DataBase named "empleados" and "fichajes". empleados has the employees data and fichajes has the date and time from when they started working. I want to get the total work time done by a specific employee between…
Aldimir
  • 193
  • 1
  • 2
  • 16
1
vote
1 answer

How to use "Try" Postgres Advisory Locks

I am experiencing some unexpected (to me) behavior using pg_try_advisory_lock. I believe this may be connection pooling / timeout related. pg_advisory_lock is working as expected. When I call the function and the desired lock is already in use, my…
jcg359
  • 21
  • 5
1
vote
1 answer

Can I use Dapper to map SQL tables with multiple relationships?

I'm developing a C# WPF desktop application where I need to read/write to an SQL database (SQL server) regularly. Now I want to map the data from the database to objects in C#. I can't use Entity Framework so I'm doing all my data access through…
maxiangelo
  • 125
  • 12
1
vote
2 answers

'Must declare the scalar variable "@SKU".'

I am using dapper to insert to a database, have been looking at my code to find what has happened, could not find anything out of the ordinary. The code works with the SELECT statement, but not when I do an insert I always get the…
bob mason
  • 677
  • 1
  • 6
  • 11
1
vote
1 answer

Sql Query with Dapper returns an empty result, but the request result from profiler is not empty

I have the SQL Query made with dapper, and its return an empty result. But if i run the SQL Profiler and execute request that i see there the result would be not empty. Here is my code public class Parameters { public DateTime?…
Andrey Dengin
  • 181
  • 2
  • 15
1 2 3
99
100