mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-25 01:14:33 +08:00
Code optimization
This commit is contained in:
parent
f6dd14c66b
commit
4964904f2f
@ -596,14 +596,9 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual int Count()
|
public virtual int Count()
|
||||||
{
|
{
|
||||||
MappingTableList expMapping = new MappingTableList();
|
MappingTableList expMapping;
|
||||||
if (QueryBuilder.EntityName== "ExpandoObject" && this.Context.MappingTables.Any(it => it.EntityName == "ExpandoObject"))
|
int result;
|
||||||
{
|
_CountBegin(out expMapping, out result);
|
||||||
expMapping.Add("ExpandoObject", this.Context.MappingTables.First(it => it.EntityName == "ExpandoObject").DbTableName);
|
|
||||||
}
|
|
||||||
InitMapping();
|
|
||||||
QueryBuilder.IsCount = true;
|
|
||||||
int result = 0;
|
|
||||||
if (IsCache)
|
if (IsCache)
|
||||||
{
|
{
|
||||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||||
@ -613,16 +608,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result = GetCount();
|
result = GetCount();
|
||||||
}
|
}
|
||||||
RestoreMapping();
|
_CountEnd(expMapping);
|
||||||
QueryBuilder.IsCount = false;
|
|
||||||
if (expMapping.Count > 0)
|
|
||||||
{
|
|
||||||
if (this.QueryableMappingTableList == null)
|
|
||||||
{
|
|
||||||
this.QueryableMappingTableList = new MappingTableList();
|
|
||||||
}
|
|
||||||
this.QueryableMappingTableList.Add(expMapping.First());
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,9 +910,9 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public async Task<int> CountAsync()
|
public async Task<int> CountAsync()
|
||||||
{
|
{
|
||||||
InitMapping();
|
MappingTableList expMapping;
|
||||||
QueryBuilder.IsCount = true;
|
int result;
|
||||||
int result = 0;
|
_CountBegin(out expMapping, out result);
|
||||||
if (IsCache)
|
if (IsCache)
|
||||||
{
|
{
|
||||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||||
@ -936,8 +922,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result =await GetCountAsync();
|
result =await GetCountAsync();
|
||||||
}
|
}
|
||||||
RestoreMapping();
|
_CountEnd(expMapping);
|
||||||
QueryBuilder.IsCount = false;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public async Task<int> CountAsync(Expression<Func<T, bool>> expression)
|
public async Task<int> CountAsync(Expression<Func<T, bool>> expression)
|
||||||
@ -1070,7 +1055,31 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
private void _CountEnd(MappingTableList expMapping)
|
||||||
|
{
|
||||||
|
RestoreMapping();
|
||||||
|
QueryBuilder.IsCount = false;
|
||||||
|
if (expMapping.Count > 0)
|
||||||
|
{
|
||||||
|
if (this.QueryableMappingTableList == null)
|
||||||
|
{
|
||||||
|
this.QueryableMappingTableList = new MappingTableList();
|
||||||
|
}
|
||||||
|
this.QueryableMappingTableList.Add(expMapping.First());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _CountBegin(out MappingTableList expMapping, out int result)
|
||||||
|
{
|
||||||
|
expMapping = new MappingTableList();
|
||||||
|
if (QueryBuilder.EntityName == "ExpandoObject" && this.Context.MappingTables.Any(it => it.EntityName == "ExpandoObject"))
|
||||||
|
{
|
||||||
|
expMapping.Add("ExpandoObject", this.Context.MappingTables.First(it => it.EntityName == "ExpandoObject").DbTableName);
|
||||||
|
}
|
||||||
|
InitMapping();
|
||||||
|
QueryBuilder.IsCount = true;
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
protected ISugarQueryable<TResult> _Select<TResult>(Expression expression)
|
protected ISugarQueryable<TResult> _Select<TResult>(Expression expression)
|
||||||
{
|
{
|
||||||
QueryBuilder.CheckExpression(expression, "Select");
|
QueryBuilder.CheckExpression(expression, "Select");
|
||||||
|
Loading…
Reference in New Issue
Block a user