Dapper.Extension.AspNetCore.MySql 1.0.2

dotnet add package Dapper.Extension.AspNetCore.MySql --version 1.0.2                
NuGet\Install-Package Dapper.Extension.AspNetCore.MySql -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dapper.Extension.AspNetCore.MySql" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dapper.Extension.AspNetCore.MySql --version 1.0.2                
#r "nuget: Dapper.Extension.AspNetCore.MySql, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Dapper.Extension.AspNetCore.MySql as a Cake Addin
#addin nuget:?package=Dapper.Extension.AspNetCore.MySql&version=1.0.2

// Install Dapper.Extension.AspNetCore.MySql as a Cake Tool
#tool nuget:?package=Dapper.Extension.AspNetCore.MySql&version=1.0.2                

Dapper.Extension.AspNetCore.MySql

Dapper extensions of MySql Database for ASP.NET Core

Installation

For more information, please view our Getting Started guide.

https://www.nuget.org/packages/Dapper.Extension.AspNetCore.MySql

PM> Install-Package Dapper.Extension.AspNetCore.MySql

Configure

  • Add the AddDapperForMySql() call into your ConfigureServices method of the Startup class.
using Microsoft.Extensions.DependencyInjection;

public class Startup
{
    //...

    public void ConfigureServices(IServiceCollection services)
    {
        //...

        // services.AddDapperForMySql("server=localhost;uid=root;pwd=123456;database=demo;charset=utf8mb4;");

        services.AddDapperForMySql(options =>
        {
            options.ConnectionString = Configuration.GetConnectionString("MySql");
        });

        //...
    }
}
  • appsettings.{env}.json:
{
  "ConnectionStrings": {
    "MySql": "server=localhost;uid=root;pwd=123456;database=demo;charset=utf8mb4;"
  }
}

Usage

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    private readonly IDapper _dapper;

    public WeatherForecastController(IDapper dapper)
    {
        _dapper = dapper;
    }

    [HttpGet]
    public IActionResult GetByPage(int pageIndex = 1, int pageSize = 20)
    {
        // var result = _dapper.Query<WeatherForecast>("select * from WeatherForecast;");
        // var result = _dapper.QueryFirstOrDefault<WeatherForecast>("select * from WeatherForecast;");
        // var result = _dapper.QueryFirstOrDefault<WeatherForecast>("select * from WeatherForecast where Id = @id;",new { id = 1 });
        // var result = _dapper.QuerySingleOrDefault<WeatherForecast>("select * from WeatherForecast;");
        // var result = _dapper.QueryFirstOrDefault<WeatherForecast>("select * from WeatherForecast where Id = @id;",new { id = 1 });
        // var result = _dapper.QueryPlainPage<WeatherForecast>("select * from WeatherForecast limit @Skip,@Take;", pageIndex, pageSize);
        var result = _dapper.QueryPage<WeatherForecast>("select count(*) from WeatherForecast;", "select * from WeatherForecast limit @Take OFFSET @Skip;", pageIndex, pageSize);
        return Ok(result);
    }

    [HttpGet("{id}")]
    public IActionResult GetById(int id)
    {
        var result = _dapper.Get<WeatherForecast>(id);
        return Ok(result);
    }

    [HttpPost]
    public void Post()
    {
        var rng = new Random();
        _dapper.Insert(new WeatherForecast
        {
            Date = DateTime.Now.AddDays(rng.Next(Summaries.Length)),
            TemperatureC = rng.Next(-20, 55),
            Summary = Summaries[rng.Next(Summaries.Length)]
        });
    }

    [HttpDelete("id")]
    public void Delete(int id)
    {
        _dapper.Delete(new WeatherForecast() { Id = id });
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 758 5/11/2022
1.0.1 835 12/11/2020

Add .net6.0 support.