mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Update queryable.ToSql()
This commit is contained in:
parent
2babcd9be7
commit
e7ed715874
@ -22,7 +22,6 @@ namespace OrmTest
|
|||||||
public void Test()
|
public void Test()
|
||||||
{
|
{
|
||||||
base.db.BeginTran();
|
base.db.BeginTran();
|
||||||
|
|
||||||
base.GetList(); //调用内部仓储方法
|
base.GetList(); //调用内部仓储方法
|
||||||
base.ChangeRepository<Repository<C2Table>>().GetList();//调用外部仓储
|
base.ChangeRepository<Repository<C2Table>>().GetList();//调用外部仓储
|
||||||
|
|
||||||
@ -57,7 +56,8 @@ namespace OrmTest
|
|||||||
|
|
||||||
var configId = typeof(T).GetCustomAttribute<TenantAttribute>().configId;
|
var configId = typeof(T).GetCustomAttribute<TenantAttribute>().configId;
|
||||||
Context = db.GetConnection(configId);
|
Context = db.GetConnection(configId);
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
this.db.CodeFirst.InitTables<T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,11 +1177,16 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||||
{
|
{
|
||||||
InitMapping();
|
if (!QueryBuilder.IsClone)
|
||||||
ToSqlBefore();
|
{
|
||||||
string sql = QueryBuilder.ToSqlString();
|
var newQueryable = this.Clone();
|
||||||
RestoreMapping();
|
newQueryable.QueryBuilder.IsClone = true;
|
||||||
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
|
return newQueryable.ToSql();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _ToSql();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
||||||
{
|
{
|
||||||
@ -1464,6 +1469,14 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
public virtual KeyValuePair<string, List<SugarParameter>> _ToSql()
|
||||||
|
{
|
||||||
|
InitMapping();
|
||||||
|
ToSqlBefore();
|
||||||
|
string sql = QueryBuilder.ToSqlString();
|
||||||
|
RestoreMapping();
|
||||||
|
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
|
||||||
|
}
|
||||||
private List<T> GetChildList(Expression<Func<T, object>> parentIdExpression, string pkName, List<T> list, object rootValue,bool isRoot=true)
|
private List<T> GetChildList(Expression<Func<T, object>> parentIdExpression, string pkName, List<T> list, object rootValue,bool isRoot=true)
|
||||||
{
|
{
|
||||||
var exp = (parentIdExpression as LambdaExpression).Body;
|
var exp = (parentIdExpression as LambdaExpression).Body;
|
||||||
|
@ -646,6 +646,10 @@ namespace SqlSugar
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region NoCopy
|
||||||
|
internal bool IsClone { get; set; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
private string GetTableName(string entityName)
|
private string GetTableName(string entityName)
|
||||||
{
|
{
|
||||||
if (this.AsTables != null && this.AsTables.Any(it=>it.Key==entityName))
|
if (this.AsTables != null && this.AsTables.Any(it=>it.Key==entityName))
|
||||||
|
Loading…
Reference in New Issue
Block a user