Scroll to top

Dapper.NET


Category

Dapper.NET : Temp Tables

How to work with temp tables The point about temporary tables is that they’re limited to the scope of the connection. Dapper will automatically open and close…

Curious Bot December 1, 2018

Dapper.NET : Transactions

Using a Transaction This example uses SqlConnection, but any IDbConnection is supported. Also any IDbTransaction is supported from the related IDbConnection. public…

Curious Bot December 1, 2018

Dapper.NET : Bulk inserts

Async Bulk Copy This sample uses a ToDataReader method described here Creating a Generic List DataReader for SqlBulkCopy. This can also be done using non-async methods.…

Curious Bot December 1, 2018

Dapper.NET : Using Async

Calling a Stored Procedure public async Task<Product> GetProductAsync(string productId) { using (_db) { return await _db.QueryFirstOrDefaultAsync<Product>("usp_GetProduct",…

Curious Bot December 1, 2018

Dapper.NET : Using DbGeography and DbGeometry

Configuration required install the required Microsoft.SqlServer.Types assembly; they are not installed by default, and are available from Microsoft here as "Microsoft®…

Curious Bot December 1, 2018

Dapper.NET : Multimapping

Simple multi-table mapping Let’s say we have a query of the remaining horsemen that needs to populate a Person class. Name Born Residence Daniel Dennett 1942…

Curious Bot December 1, 2018

Dapper.NET : Dynamic Parameters

Basic Usage It isn’t always possible to neatly package all the parameters up in a single object / call. To help with more complicated scenarios, dapper allows…

Curious Bot December 1, 2018

Dapper.NET : Handling Nulls

null vs DBNull In ADO.NET, correctly handling null is a constant source of confusion. The key point in dapper is that you don’t have to; it deals with it all…

Curious Bot December 1, 2018

Dapper.NET : Multiple Results

Base Multiple Results Example To fetch multiple grids in a single query, the QueryMultiple method is used. This then allows you to retrieve each grid sequentially…

Curious Bot December 1, 2018

Dapper.NET : Parameter Syntax Reference

Basic Parameterized SQL Dapper makes it easy to follow best practice by way of fully parameterized SQL. Parameters are important, so dapper makes it easy to get…

Curious Bot December 1, 2018

Dapper.NET : Getting started with Dapper.NET

Install Dapper from Nuget Either search in the Visual Studio GUI: Tools > NuGet Package Manager > Manage Packages for Solution… (Visual Studio 2015)…

Curious Bot December 1, 2018

Dapper.NET : Basic Querying

Querying for a static type For types known at compile-time, use a generic parameter with Query<T>. public class Dog { public int? Age { get; set; } public…

Curious Bot December 1, 2018

Dapper.NET : Executing Commands

Execute a command that returns no results IDBConnection db = /* ... */ var id = /* ... */ db.Execute(@"update dbo.Dogs set Name = 'Beowoof' where Id = @id",…

Curious Bot December 1, 2018

Dapper.NET : Type Handlers

Converting varchar to IHtmlString public class IHtmlStringTypeHandler : SqlMapper.TypeHandler<IHtmlString> { public override void SetValue( IDbDataParameter…

Curious Bot December 1, 2018