添加Dapper
This commit is contained in:
@@ -7,7 +7,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dapper;
|
||||
namespace LeadDataBaseUtility
|
||||
{
|
||||
/// <summary>
|
||||
@@ -16,9 +16,27 @@ namespace LeadDataBaseUtility
|
||||
/// 允许修改、添加满足自己项目的需要。
|
||||
/// 添加、修改后请详细注释。违者会强制删除不予采用。
|
||||
/// </summary>
|
||||
public abstract class LeadDbHelperSQLite
|
||||
public static class LeadDbHelperSQLite
|
||||
{
|
||||
public static string connectionString = LeadConfigureConnectionString.getConnectionString("LeadSQLite");
|
||||
static LeadDbHelperSQLite()
|
||||
{
|
||||
|
||||
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static int ExecuteSql(string sql, object param = null)
|
||||
{
|
||||
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
|
||||
{
|
||||
return conn.Execute(sql, param);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 对SQLite数据库执行增删改操作,返回受影响的行数。
|
||||
@@ -52,6 +70,18 @@ namespace LeadDataBaseUtility
|
||||
#endif
|
||||
return affectedRows;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> Query<T>(string Strsql, object Param = null)
|
||||
{
|
||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||
{
|
||||
|
||||
return connection.Query<T>(Strsql, Param);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询语句,返回DataSet
|
||||
/// </summary>
|
||||
@@ -80,6 +110,16 @@ namespace LeadDataBaseUtility
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
public static T GetSingle<T>(string SQLString, object Param = null)
|
||||
{
|
||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||
{
|
||||
return connection.QueryFirstOrDefault<T>(SQLString, Param);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行一条计算查询结果语句,返回查询结果(object)。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user