CBLibrary.Dapper 1.0.1

Dapper操作MSSQL或MySQL基类封装(推荐配合Dommel组件使用), 具体使用方法请参阅README.md说明或者联系作者

Install-Package CBLibrary.Dapper -Version 1.0.1
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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);
        }
    }

}

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);
        }
    }

}

Release Notes

新增DapperBase抽象类

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 101 1/29/2019
1.0.0 113 1/28/2019