eminemjk / banana Goto Github PK
View Code? Open in Web Editor NEW🍌 The collection of CRUD helpers for Dapper.
License: MIT License
🍌 The collection of CRUD helpers for Dapper.
License: MIT License
Can you please make separate English documentation and make all the code comments in English?
你好, 我看了一下代码,pgsql数据库的 组织SQL分支针对字段有双引号的, 这样导致实体和数据库字段大小写必要一致才行, 原来在dapper的issues提过一直没解决
你的代码中包含了一些隐私信息,包含redis中配置的IP地址等私密信息,大兄弟及时修改啊!
请问类似
var list = repo.QueryList("Name like @name", new { Name = "%EminemJK%" });
@占位符针对不同类型数据库是否需要写不同的分支?
[Computed] public string TableName { get; set; }
调用repo.QueryList发现就报错了, TableName列不存在,
这个attribute不是标记列不放到select中的吗?
环境
DotnetCore 2.2
Oracle 10g
你好,在开发途中发现两个问题。
OracleAdapter 198行,当不传入分页时默认采用"ID"来排序,但表主键不一定叫ID,建议取Entity中 KeyAttribute 中标的列作默认排序列以免发生错误。
string orderSql = "ID";
if (order != null)
{
orderSql = SqlBuilder.GetArgsString("ORDER BY", prefix: repository.TableName, args: order);
}
private static void TestOracleAdapter()
{
OracleAdapter oracleAdapter = new OracleAdapter();
var sqlbuilder = oracleAdapter.GetPageList(new Repository<UserInfo>(),
pageNum: 1,
pageSize: 10,
order: "Name",
whereString: "Name=@Name and Phone=@Phone",
param: new { Name = "tom", Phone = "123456" });
// 访问SQL属性时会报 System.ArgumentOutOfRangeException:“Specified argument was out of the range of valid values.
Arg_ParamName_Name
var sql = sqlbuilder.SQL;
}
以OracleAdapter为例,调试发现是这行 210
sqlBuilderRows.From(repository.TableName);
if (!string.IsNullOrEmpty(whereString))
{
sqlBuilderRows.Where(whereString, param);
}
// sqlBuilderRows.Arguments 传入后访问sqlBuilder.SQL 则会报此异常 把参数改为 param 则正常,由于急着用没深究原因
sqlBuilder.Append($"From ({sqlBuilderRows.SQL}) TT", sqlBuilderRows.Arguments);
你好,在开发中发现有一个问题及一个小提议。 : )
1.在 OracleAdapter 中 以下这个抛出的异常,请问能否变动其逻辑会更好呢?现在程序的逻辑为假定 Model 标记了 Key 则必须标记 Sequence 否则则会报以下异常,但实际情况可能是表不一定向Sequence取ID来赋值,可能使用的是GUID键。
总结:Model 主键自己赋值,并非Sequence取值时,只标识Key但不指定Sequence会报以下异常
if (propertyInfos.Length == 0 || string.IsNullOrEmpty(oracleSequence))
{
// 由于以上原因是否这里插入时 {columnlist}\{parameterList} 也应该把标识为KEY的列加上呢?
cmd = $"insert into {tableName} ({columnList}) values ({parameterList})";
}
else
{
// 指定了KEY,但由于主键并不一定为oracleSequence中取值,不指定oracleSequence 则报异常
if (string.IsNullOrEmpty(oracleSequence))
throw new Exception("KeyAttribute's OracleSequence is Null");
// ... 省略无关代码
}
运行环境
你好,我尝试按以下代码运行报错,发现在UOW中运行时一旦查询则会报以下错误
using (UnitOfWork uow = new UnitOfWork())
{
var studentRepo = uow.Repository<Student>();
// Query 会报错 ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized
var student = studentRepo.Query(1);
// 做一些更新student的一些属性值....
if (studentRepo.Update(student))
{
uow.Commit();
}
else
{
uow.Rollback();
}
}
查看Repository的源码发现与查询相关的Query,Page 等与事务对象是没有关联的,只有Insert,Update,Delete 等与事务是有关联的。请问出于何种原因UOW中把查询设计成与事务无关呢?
若存在UOW中需要查询的情况该如何应对?希望能指导一二,谢谢。
如果要查的数据与本次事务无关的我是否只能按以下方式?若某些需要查询的数据是在前一步Insert或Update后才存在呢?以下方式就实现不了了。
var studenRepo = new Repository<Student>();
var student = studentRepo.Query(1);
using (UnitOfWork uow = new UnitOfWork())
{
// 做一些更新student的一些属性值....
studentRepo = uow.Repository<Student>();
if (studentRepo.Update(student))
{
uow.Commit();
}
else
{
uow.Rollback();
}
}
你好,请问是否可以就关于数据库连接释放时机的问题进行讨论呢,或晚上下班后QQ讨论呢?
关于连接的创建,现在是在 ConnectionBuilder.cs 中进行统一的连接创建
public static IDbConnection CreateConnection(string dbAliase = DefaultAliase)
{
try
{
if (string.IsNullOrEmpty(dbAliase))
{
dbAliase = DefaultAliase;
}
DBSetting dBSetting;
if (!DBSettingDic.TryGetValue(dbAliase, out dBSetting))
{
throw new Exception("The key doesn't exist:" + dbAliase);
}
var conn = dBSetting.ConnectionString;
switch (dBSetting.DBType)
{
// 以下直接创建连接
case DBType.SqlServer:
case DBType.SqlServer2012:
return new SqlConnection(conn);
case DBType.MySQL:
return new MySqlConnection(conn);
case DBType.SQLite:
return new SQLiteConnection(conn);
case DBType.Postgres:
return new NpgsqlConnection(conn);
case DBType.Oracle:
return new OracleConnection(conn);
}
// 省略其余代码
Repo的基类,目前是以这种方式直接创建使用的,但我发现数据连接的整个使用周期没有发现释放或Close的代码,这样将会导致连接一直被占用,一旦访问超过连接池中数量则会出现连接不上数据库的异常,原因在于池中所有连接都被占用没被释放。以上结论是我手动把连接池限制到10个连接时测试得出。
/// <summary>
/// IDbConnection
/// </summary>
public IDbConnection DBConnection
{
get
{
if (_dbConnection == null)
{
// 创建连接 但 最终并没释放
_dbConnection = ConnectionBuilder.CreateConnection(dbAliase);
}
if (_dbConnection.State == ConnectionState.Closed && _dbConnection.State != ConnectionState.Connecting)
{
_dbConnection.Open();
}
return _dbConnection;
}
private set { this._dbConnection = value; }
}
目前我的解决方式,我把基础的Repo 实现 IDisposable 使用USING 或 手动释放连接,但这种方式感觉写起来有点麻烦,所以想与你讨论下是否有或好的方式在整个连接的使用周期内释放连接的方法?
这个表是3个列一起作为主键的,不是使用Sequence,也不是使用guid
var repo = new Repository<ErmItem>(); List<ErmItem> list = null; //查询列表 if (ConnectionBuilder.GetDBSetting().DBType == Banana.Uow.Models.DBType.Oracle) { list = repo.QueryList("LastModifyTime>:indexDate", new { indexDate }); } else list = repo.QueryList("LastModifyTime>@indexDate", new { indexDate });
SqlServer下正常
你好
是否支持TransactionScope这种方式的事务支持吗, 在里面使用repository类操作?
The MySqlAdapter code uses ExecuteAsync
, etc.. It's a long-standing bug in MySql.Data (bug 70111) that async I/O is not implemented correctly; thus this method will actually run synchronously. (See also here and here on Stack Overflow.)
To fix this, you could switch to https://github.com/mysql-net/MySqlConnector, an OSS replacement for MySql.Data that supports true asynchronous I/O.
If you're interested in this, I'd be happy to open a PR.
using Dapper.Contrib.Extensions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.