CBLibrary.Dapper 1.0.1

.NET Framework 4.5.1
NuGet\Install-Package CBLibrary.Dapper -Version 1.0.1
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.
dotnet add package CBLibrary.Dapper --version 1.0.1
<PackageReference Include="CBLibrary.Dapper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CBLibrary.Dapper --version 1.0.1
#r "nuget: CBLibrary.Dapper, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.1

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

Dapper操作MSSQL或MYSQL基类封装

CBLibrary.Dapper 1.0.1

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 Versions
.NET Framework net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
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 534 1/29/2019
1.0.0 489 1/28/2019

新增DapperBase抽象类