GodSharp.Data.Dapper
DbContext for Dapper.
Install / Use
/learn @godsharp/GodSharp.Data.DapperREADME
GodSharp.Data.Dapper
DbContext for Dapper.
Supported .NET Version
- .NET Framework 3.5+
- .NET Standard 1.3
- .NET Standard 2.0
Getting Started
- Install Nuget Package.
See here.
- Inherited class
DapperDbContext.
Use connectionString name in App.Config or Web.config as constructor parameters.
If your project type is .NET Core,you should add json setting for connectionStrings and DbConnectionFactories,format reference here.
public class IRepository:DbContext
{
public IRepository():base("db")
{
}
}
Or override OnConfiguration method, invoke Use method.
public class IRepository : DbContext
{
public IRepository()
{
}
protected override void OnConfiguration(DbConnectionFactory factory)
{
base.OnConfiguration(factory);
string providerName= "MySql.Data.MySqlClient";
string connectionString= "Data Source=127.0.0.1;Initial Catalog=user;User Id=root;Password=root;Charset=utf8;";
factory.Use(providerName, connectionString);
}
}
- Define data objects.
public class TestRepository : IRepository
{
public bool Connected()
{
try
{
object obj = ExecuteScalar("SELECT CONVERT(varchar(50), GETDATE(), 25);", null, null, CommandType.Text);
if (obj == null)
{
return false;
}
string dt = obj.ToString();
DateTime _dt;
return DateTime.TryParse(dt, out _dt);
}
catch (Exception ex)
{
throw ex;
}
}
}
Execute Sql with transaction.
public class TestRepository : IRepository
{
public bool ExecuteWithTran()
{
string sql = null;
object param = null;
// begin tran
BeginTransaction();
// execute sql
Execute(sql, param);
// commit tran
Commit();
// or
// callback tran
//Callback();
}
}
License
Licensed under the MIT License.
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.6kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
