在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:GodSharp.Data.Dapper开源软件地址:https://gitee.com/GodSharp/GodSharp.Data.Dapper开源软件介绍:GodSharp.Data.DapperDbContext for Dapper. Supported .NET Version
Getting Started
See here.
Use connectionString name in If your project type is public class IRepository:DbContext{ public IRepository():base("db") { }} Or override 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); }}
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(); }} LicenseLicensed under the MIT License. |
请发表评论