1.15.0
数据库连接配置:
{
"ConnectionConfigs": [
{
"ConfigId": "testgoods",
"ConnectionString": "",
"DbType": "MySql",
"IsAutoCloseConnection": true,
"InitKeyType": "Attribute"
},
{
"ConfigId": "taihedb",
"ConnectionString": "",
"DbType": "MySql",
"IsAutoCloseConnection": true,
"InitKeyType": "Attribute"
}
]
}
代码实现:
List<ConnectionConfig> connectionConfigs = App.GetConfig<List<ConnectionConfig>>("ConnectionConfigs");
services.AddSqlSugar(connectionConfigs.ToArray(), db => db.Aop.OnLogExecuting = (sql, pars) => {
string parsInfo = string.Empty;
if (0 != pars.Length) {
parsInfo = string.Join(",", pars?.Select(it => it.ParameterName + ": " + it.Value + (null == it.Value ? string.Empty : string.Format("({0})", it.Value.GetType().Name))));
}
Debug.WriteLine(sql);
Debug.WriteLineIf(0 != pars.Length, parsInfo);
App.PrintToMiniProfiler("SqlSugar", "Info", sql + (0 == pars.Length ? string.Empty : ("\r\n" + parsInfo)));
});
两个库分别执行SQL语句。
// "ConfigId": "testgoods"
var list1 = db.Queryable<dynamic>().AS("js_gen_table").ToList();
// "ConfigId": "taihedb",
var list2 = (db as SqlSugarClient).GetConnection("taihedb").Queryable<dynamic>().AS("js_sys_company").ToList();
问题是执行第二个查询语句不能打印SQL语句。
在别的项目测试 SqlSugar, 多个数据库是可以打印SQL语句。
请教是我代码实现有问题吗?如果我代码实现有问题,应该如何实现。
多个数据库都能打印SQL语句。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
能否写一个其他项目正常的例子我?弄一个git仓库,我去看看。不用furion的版本。
@百小僧
SqlSugarClient client = new SqlSugarClient(new ConnectionConfig() {
ConfigId = "testgoods",
ConnectionString = "",//连接符字串
DbType = SqlSugar.DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute, //从特性读取主键自增信息
AopEvents = new AopEvents {
OnLogExecuting = (sql, p) => {
Debug.WriteLine("testgoods => " + sql);
Debug.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
}); ;
client.AddConnection(new ConnectionConfig() {
ConfigId = "taihedb",
ConnectionString = "",//连接符字串
DbType = SqlSugar.DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute, //从特性读取主键自增信息
AopEvents = new AopEvents {
OnLogExecuting = (sql, p) => {
Debug.WriteLine("taihedb => " + sql);
Debug.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
});
var list1 = client.Queryable().AS("js_gen_table").ToList();
var list2 = client.GetConnection("taihedb").Queryable().AS("js_sys_company").ToList();
List connectionConfigs = App.GetConfig<List>("ConnectionConfigs");
connectionConfigs[0].AopEvents = new AopEvents {
OnLogExecuting = (sql, pars) => {
#if DEBUG
string configId = "“SqlSugar testgoods” ";
string parsInfo = string.Empty;
if (0 != pars.Length) {
parsInfo = string.Join(",", pars?.Select(it => it.ParameterName + ": " + it.Value + (null == it.Value ? string.Empty : string.Format("({0})", it.Value.GetType().Name))));
}
Debug.WriteLine(configId + sql);
if (0 != pars.Length) Debug.WriteLine(configId + parsInfo);
App.PrintToMiniProfiler("SqlSugar", "Info", sql + (0 == pars.Length ? string.Empty : ("\r\n" + parsInfo)));
#endif
}
};
services.AddSqlSugar(connectionConfigs[0]);
connectionConfigs[1].AopEvents = new AopEvents {
OnLogExecuting = (sql, pars) => {
#if DEBUG
string configId = "“SqlSugar taihedb” ";
string parsInfo = string.Empty;
if (0 != pars.Length) {
parsInfo = string.Join(",", pars?.Select(it => it.ParameterName + ": " + it.Value + (null == it.Value ? string.Empty : string.Format("({0})", it.Value.GetType().Name))));
}
Debug.WriteLine(configId + sql);
if (0 != pars.Length) Debug.WriteLine(configId + parsInfo);
App.PrintToMiniProfiler("SqlSugar", "Info", sql + (0 == pars.Length ? string.Empty : ("\r\n" + parsInfo)));
#endif
}
};
services.AddSqlSugar(connectionConfigs[1]);
登录 后才可以发表评论