/dapper-samples

Tutorial samples that shows how to use Dapper .NET

Primary LanguageC#Apache License 2.0Apache-2.0

Dapper .NET Samples

Samples that shows how to use Dapper .NET.

These are the samples mentioned in the Dapper .Net publication on Medium:

https://medium.com/dapper-net

Work is still in progress, so come back often to check out new articles and samples. My aim to to publish one article per week, until all feature of Dapper are covered.

Here's the list of samples related to articles published so far:

  1. Getting Started with Dapper .NET
  2. Multiple Executions
  3. Multiple Resultsets
  4. Multiple Mapping
  5. SQL Server Features
  6. Custom Mapping
  7. Custom Handling
  8. One-To-Many Relationships
  9. Complex Custom Handling

Please note that the "One-To-Many Relatioships" and "Complex Custom Handling" points to the same articles since both topics are discussed there as they are strictly related to each other.

Running The Samples

To run the "Basic Samples", related to the first article "Getting Started with Dapper .NET", just run

dotnet run -f net452

from

Dapper.Samples.Basics

folder. To run advanced samples you have to move into

Dapper.Samples.Advanced

and then from here you can just run

dotnet run -f net452

to run ALL samples or

dotnet run -f net452 "Sample Name"

to run that specific sample. Eg:

dotnet run -f net452 "Multiple Executions"

to run only the "Multiple Execution" sample.

To have a list of all advanced samples available run:

dotnet run -f net452 -help

Notes

.NET Version

Samples are done using .NET Core 2.0 and .NET Framework 4.5.2: make sure you have them installed it on your machine.

In order to use features not yet supported by .NET Core 2.0, like SQL Server Spatial Data Types, the project supports multiple targets:

  • net452
  • netcoreapp2.0

To execute the application targeting one specifc framework, just use the -f option when running the console app:

dotnet run -f net452

more info on the -f option here:

dotnet run

SQL Server

Samples also use SQL Server as database server. If you don't have a Windows machine, you can use the Docker version: SQL Server 2017. SQL Server database file is attached automatically using the LocalDB/MSSQLServer instance. If you prefer to use a non-local instance, make sure you change the connection string accordingly, and attach the database file to your instance.