mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-21 02:58:05 +08:00
-
This commit is contained in:
@@ -72,8 +72,8 @@ namespace OrmTest.UnitTest
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||
db.Database.IsEnableLogEvent = true;
|
||||
db.Database.LogEventStarting = (sql, pars) =>
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
@@ -30,7 +30,7 @@ namespace OrmTest.UnitTest
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
//db.Database.IsEnableLogEvent = true;
|
||||
db.Database.LogEventStarting = (sql, pars) =>
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
@@ -59,7 +59,7 @@ namespace OrmTest.UnitTest
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [Id] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", null, s6.Key, null, "s6 Error");
|
||||
|
||||
|
||||
int studentCount=db.Database.GetInt("select count(1) from Student");
|
||||
int studentCount=db.Ado.GetInt("select count(1) from Student");
|
||||
var countIsSuccess=db.Queryable<Student>().Count()== studentCount;
|
||||
if (!countIsSuccess) {
|
||||
throw new Exception("countIsSuccess Error");
|
||||
@@ -72,28 +72,28 @@ namespace OrmTest.UnitTest
|
||||
throw new Exception("s7 Error");
|
||||
}
|
||||
|
||||
int studentMin = db.Database.GetInt("select min(id) from Student");
|
||||
int studentMin = db.Ado.GetInt("select min(id) from Student");
|
||||
var minIsSuccess = db.Queryable<Student>().Min(it=>it.Id) == studentMin;
|
||||
if (!minIsSuccess)
|
||||
{
|
||||
throw new Exception("minIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentMax = db.Database.GetInt("select max(id) from Student");
|
||||
int studentMax = db.Ado.GetInt("select max(id) from Student");
|
||||
var maxIsSuccess = db.Queryable<Student>().Max(it => it.Id) == studentMax;
|
||||
if (!maxIsSuccess)
|
||||
{
|
||||
throw new Exception("maxIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentAvg = db.Database.GetInt("select avg(id) from Student");
|
||||
int studentAvg = db.Ado.GetInt("select avg(id) from Student");
|
||||
var avgIsSuccess = db.Queryable<Student>().Avg(it => it.Id) == studentAvg;
|
||||
if (!maxIsSuccess)
|
||||
{
|
||||
throw new Exception("avgIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentSum = db.Database.GetInt("select sum(id) from Student");
|
||||
int studentSum = db.Ado.GetInt("select sum(id) from Student");
|
||||
var sumIsSuccess = db.Queryable<Student>().Sum(it => it.Id) == studentSum;
|
||||
if (!sumIsSuccess)
|
||||
{
|
||||
|
@@ -145,7 +145,7 @@ namespace SqlSugar
|
||||
var bindType = PubMethod.GetUnderType(bindProperty, ref isNullableType);
|
||||
string dbTypeName = DataRecord.GetDataTypeName(ordinal);
|
||||
string propertyName = bindProperty.Name;
|
||||
var bind = Context.Database.DbBind;
|
||||
var bind = Context.Ado.DbBind;
|
||||
List<string> guidThrow = bind.GuidThrow;
|
||||
List<string> intThrow = bind.IntThrow;
|
||||
List<string> stringThrow = bind.StringThrow;
|
||||
|
@@ -8,7 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public abstract partial class DbProvider : DbAccessory, IDb
|
||||
public abstract partial class DbProvider : DbAccessory, IAdo
|
||||
{
|
||||
public DbProvider()
|
||||
{
|
||||
|
@@ -55,13 +55,13 @@ namespace SqlSugar
|
||||
|
||||
public virtual bool CreateTable(string tableName, List<DbColumnInfo> columns)
|
||||
{
|
||||
this.Context.Database.ExecuteCommand(this.CreateTableSql);
|
||||
this.Context.Ado.ExecuteCommand(this.CreateTableSql);
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool TruncateTable(string tableName)
|
||||
{
|
||||
this.Context.Database.ExecuteCommand(this.TruncateTableSql);
|
||||
this.Context.Ado.ExecuteCommand(this.TruncateTableSql);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ namespace SqlSugar
|
||||
|
||||
}, (cm, key) =>
|
||||
{
|
||||
var isEnableLogEvent = this.Context.Database.IsEnableLogEvent;
|
||||
this.Context.Database.IsEnableLogEvent = false;
|
||||
var reval = this.Context.Database.SqlQuery<T>(this.GetColumnInfosByTableNameSql);
|
||||
this.Context.Database.IsEnableLogEvent = isEnableLogEvent;
|
||||
var isEnableLogEvent = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var reval = this.Context.Ado.SqlQuery<T>(this.GetColumnInfosByTableNameSql);
|
||||
this.Context.Ado.IsEnableLogEvent = isEnableLogEvent;
|
||||
return reval;
|
||||
});
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
public class DeleteableProvider<T> : IDeleteable<T> where T : class, new()
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public IDb Db { get { return Context.Database; } }
|
||||
public IAdo Db { get { return Context.Ado; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public DeleteBuilder DeleteBuilder { get; set; }
|
||||
public EntityInfo EntityInfo
|
||||
@@ -101,7 +101,7 @@ namespace SqlSugar
|
||||
DeleteBuilder.WhereInfos.Add(whereString);
|
||||
if (whereObj != null)
|
||||
{
|
||||
DeleteBuilder.Parameters.AddRange(Context.Database.GetParameters(whereObj));
|
||||
DeleteBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
public class InsertableProvider<T> : IInsertable<T> where T : class, new()
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public IDb Db { get { return Context.Database; } }
|
||||
public IAdo Db { get { return Context.Ado; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public InsertBuilder InsertBuilder { get; set; }
|
||||
|
||||
|
@@ -13,7 +13,7 @@ namespace SqlSugar
|
||||
public partial class QueryableProvider<T> : QueryableAccessory, ISugarQueryable<T>
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public IDb Db { get { return Context.Database; } }
|
||||
public IAdo Db { get { return Context.Ado; } }
|
||||
public IDbBind Bind { get { return this.Db.DbBind; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public QueryBuilder QueryBuilder
|
||||
@@ -36,7 +36,7 @@ namespace SqlSugar
|
||||
public ISugarQueryable<T> AddParameters(object whereObj)
|
||||
{
|
||||
if (whereObj != null)
|
||||
QueryBuilder.Parameters.AddRange(Context.Database.GetParameters(whereObj));
|
||||
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T> AddParameters(SugarParameter[] pars)
|
||||
@@ -76,7 +76,7 @@ namespace SqlSugar
|
||||
var whereValue = QueryBuilder.WhereInfos;
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString));
|
||||
if (whereObj != null)
|
||||
QueryBuilder.Parameters.AddRange(Context.Database.GetParameters(whereObj));
|
||||
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T> Where<T2>(Expression<Func<T2, bool>> expression)
|
||||
@@ -114,7 +114,7 @@ namespace SqlSugar
|
||||
|
||||
QueryBuilder.HavingInfos = SqlBuilder.AppendHaving(whereString);
|
||||
if (whereObj != null)
|
||||
QueryBuilder.Parameters.AddRange(Context.Database.GetParameters(whereObj));
|
||||
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T> Having<T2>(Expression<Func<T2, bool>> expression)
|
||||
@@ -427,7 +427,7 @@ namespace SqlSugar
|
||||
{
|
||||
QueryBuilder.IsCount = true;
|
||||
var sql = QueryBuilder.ToSqlString();
|
||||
var reval = Context.Database.GetInt(sql, QueryBuilder.Parameters.ToArray());
|
||||
var reval = Context.Ado.GetInt(sql, QueryBuilder.Parameters.ToArray());
|
||||
QueryBuilder.IsCount = false;
|
||||
return reval;
|
||||
}
|
||||
|
@@ -86,10 +86,10 @@ namespace SqlSugar
|
||||
return reval;
|
||||
}
|
||||
|
||||
public static IDb GetDb(IConnectionConfig currentConnectionConfig)
|
||||
public static IAdo GetAdo(IConnectionConfig currentConnectionConfig)
|
||||
{
|
||||
CheckConfig(currentConnectionConfig);
|
||||
IDb reval = CreateInstance<IDb>(GetClassName(currentConnectionConfig.DbType, "Provider"), currentConnectionConfig.DbType);
|
||||
IAdo reval = CreateInstance<IAdo>(GetClassName(currentConnectionConfig.DbType, "Provider"), currentConnectionConfig.DbType);
|
||||
return reval;
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial interface IDb
|
||||
public partial interface IAdo
|
||||
{
|
||||
string SqlParameterKeyWord { get; }
|
||||
IDbConnection Connection { get; set; }
|
||||
|
@@ -20,7 +20,7 @@ namespace SqlSugar
|
||||
|
||||
protected ISqlBuilder _SqlBuilder;
|
||||
protected EntityProvider _EntityProvider;
|
||||
protected IDb _Ado;
|
||||
protected IAdo _Ado;
|
||||
protected ILambdaExpressions _LambdaExpressions;
|
||||
protected IRewritableMethods _RewritableMethods;
|
||||
protected IDbFirst _DbFirst;
|
||||
|
@@ -60,7 +60,7 @@ namespace SqlSugar
|
||||
base.InitConstructor();
|
||||
if (slaveConnectionConfigs.IsNullOrEmpty()) return;
|
||||
|
||||
var db = this.Database;
|
||||
var db = this.Ado;
|
||||
db.MasterConnectionConfig = masterConnectionConfig;
|
||||
db.SlaveConnectionConfigs = slaveConnectionConfigs.ToList();
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace SqlSugar
|
||||
base.InitConstructor();
|
||||
if (slaveConnectionConfigs.IsNullOrEmpty()) return;
|
||||
|
||||
var db = this.Database;
|
||||
var db = this.Ado;
|
||||
Check.ArgumentNullException(masterConnectionConfig.EntityNamespace, ErrorMessage.EntityNamespaceError);
|
||||
base.EntityNamespace = masterConnectionConfig.EntityNamespace;
|
||||
db.MasterConnectionConfig = masterConnectionConfig;
|
||||
@@ -89,13 +89,13 @@ namespace SqlSugar
|
||||
/// <summary>
|
||||
///Database operation
|
||||
/// </summary>
|
||||
public virtual IDb Database
|
||||
public virtual IAdo Ado
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Ado == null)
|
||||
{
|
||||
var reval = InstanceFactory.GetDb(base.CurrentConnectionConfig);
|
||||
var reval = InstanceFactory.GetAdo(base.CurrentConnectionConfig);
|
||||
Check.ConnectionConfig(base.CurrentConnectionConfig);
|
||||
_Ado = reval;
|
||||
reval.Context = this;
|
||||
@@ -373,16 +373,16 @@ namespace SqlSugar
|
||||
#region Dispose OR Close
|
||||
public virtual void Close()
|
||||
{
|
||||
if (this.Database != null)
|
||||
if (this.Ado != null)
|
||||
{
|
||||
this.Database.Close();
|
||||
this.Ado.Close();
|
||||
}
|
||||
}
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (this.Database != null)
|
||||
if (this.Ado != null)
|
||||
{
|
||||
this.Database.Dispose();
|
||||
this.Ado.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
Reference in New Issue
Block a user