using Dapper;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using VOL.Core.DBManager;
using VOL.Core.Extensions;
using VOL.Core.Utilities;
namespace VOL.Core.Dapper
{
public class SqlDapper : ISqlDapper
{
private string _connectionString;
private IDbConnection _connection { get; set; }
public IDbConnection Connection
{
get
{
if (_connection == null)
{
_connection = DBServerProvider.GetDbConnection(_connectionString);
}
return _connection;
}
}
public SqlDapper()
{
_connectionString = DBServerProvider.GetConnectionString();
}
///
/// string mySql = "Data Source=132.232.2.109;Database=mysql;User
/// ID=root;Password=mysql;pooling=true;CharSet=utf8;port=3306;sslmode=none";
/// this.conn = new MySql.Data.MySqlClient.MySqlConnection(mySql);
///
///
public SqlDapper(string connKeyName)
{
_connectionString = DBServerProvider.GetConnectionString(connKeyName);
}
///
/// var p = new object();
// p.Add("@a", 11);
//p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
//p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
// ///
///
///
///
///
///
public List QueryList(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) where T : class
{
return Execute((conn, dbTransaction) =>
{
return conn.Query(cmd, param, dbTransaction, commandType: commandType ?? CommandType.Text).ToList();
}, beginTransaction);
}
public T QueryFirst(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) where T : class
{
List list = QueryList(cmd, param, commandType: commandType ?? CommandType.Text, beginTransaction: beginTransaction).ToList();
return list.Count == 0 ? null : list[0];
}
public object ExecuteScalar(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false)
{
return Execute