CBLibrary.Dapper 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CBLibrary.Dapper --version 1.0.0                
NuGet\Install-Package CBLibrary.Dapper -Version 1.0.0                
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="CBLibrary.Dapper" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CBLibrary.Dapper --version 1.0.0                
#r "nuget: CBLibrary.Dapper, 1.0.0"                
#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 CBLibrary.Dapper as a Cake Addin
#addin nuget:?package=CBLibrary.Dapper&version=1.0.0

// Install CBLibrary.Dapper as a Cake Tool
#tool nuget:?package=CBLibrary.Dapper&version=1.0.0                

Dapper操作MSSQL或MYSQL基类封装

CBLibrary.Dapper 1.0.0

Release Notes

Features

  • Dapper操作MSSQL或MYSQL基类封装(推荐配合Dommel组件使用)

Usages

数据库类型-枚举
public enum EDBType
{
    /// <summary>
    /// SQLServer数据库
    /// </summary>
    MSSQL = 1,

    /// <summary>
    /// MySQL数据库
    /// </summary>
    MYSQL = 2,
}
调用示例
using Dommel;
using System;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;

public class DapperTest : DapperBase
{
    protected sealed override EDBType DbType { get; set; }
    protected sealed override string ConnectionString { get; set; }


    private static readonly string _dbType = ConfigurationManager.AppSettings["DbType"].ToUpper();

    public DapperTests()
    {
        switch (_dbType)
        {
            case "MYSQL":
                this.DbType = EDBType.MYSQL;
                this.ConnectionString = ConfigurationManager.ConnectionStrings["MYSQLConnection"].ConnectionString;
                break;
            case "MSSQL":
                this.DbType = EDBType.MSSQL;
                this.ConnectionString = ConfigurationManager.ConnectionStrings["MSSQLConnection"].ConnectionString;
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }


    public async Task AddAsync()
    {
        using (var connection = base.Connection)
        {
            var person = new Person
            {
                Name = "Tom"
            };

            var result = await connection.InsertAsync(person);
        }
    }

    public async Task QueryAsync()
    {
        using (var connection = base.Connection)
        {
            var persons = await connection.SelectAsync<Person>(p => p.Active == true);
        }
    }

    public async Task UpdateAsync()
    {
        using (var connection = base.Connection)
        {
            var person = await connection.GetAsync<Person>(2);
            person.Active = false;

            var result = await connection.UpdateAsync(person);
        }
    }

    public async Task DeleteAsync()
    {
        using (var connection = base.Connection)
        {
            var person = await connection.GetAsync<Person>(2);

            var result = await connection.DeleteAsync(person);
        }
    }

}
Product Compatible and additional computed target framework versions.
.NET Framework net451 is compatible.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.1 790 1/29/2019
1.0.0 691 1/28/2019

新增DapperBase抽象类