Browse Source

Synchronization code

pull/40/head
sunkaixuan 1 year ago
parent
commit
f141de1252
  1. 24
      Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
  2. 2
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs
  3. 24
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs
  4. 30
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs
  5. 12
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs
  6. 4
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs

24
Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs

@ -16,6 +16,30 @@ namespace SqlSugar
{
return GetEntityInfo(typeof(T));
}
public EntityInfo GetEntityInfoWithAttr(Type type)
{
var attr = type?.GetCustomAttribute<TenantAttribute>();
if (attr == null)
{
return GetEntityInfo(type);
}
else if (attr.configId.ObjToString() == this.Context?.CurrentConnectionConfig?.ConfigId+"")
{
return GetEntityInfo(type);
}
else if (this.Context.Root == null)
{
return GetEntityInfo(type);
}
else if (!this.Context.Root.IsAnyConnection(attr.configId))
{
return GetEntityInfo(type);
}
else
{
return this.Context.Root.GetConnection(attr.configId).EntityMaintenance.GetEntityInfo(type);
}
}
public EntityInfo GetEntityInfo(Type type)
{
string cacheKey = "GetEntityInfo" + type.GetHashCode() + type.FullName+this.Context?.CurrentConnectionConfig?.ConfigId;

2
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs

@ -1364,7 +1364,7 @@ namespace SqlSugar
protected string AppendSelect<EntityType>(string sql, ReadOnlyCollection<ParameterExpression> parameters, List<EntityColumnInfo> columnsResult, int parameterIndex1)
{
var columns = this.Context.EntityMaintenance.GetEntityInfo<EntityType>().Columns;
var columns = this.Context.EntityMaintenance.GetEntityInfoWithAttr(typeof(EntityType)).Columns;
var lowerSql = sql.ToLower();
var isSubquery = lowerSql.Contains("select ") && ExpressionTool.IsMemberInit(this.QueryBuilder.SelectValue);
if (isSubquery)

24
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs

@ -260,7 +260,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
@ -269,6 +269,10 @@ namespace SqlSugar
var columnsResult = this.Context.EntityMaintenance.GetEntityInfo<TResult>().Columns;
sql = AppendSelect<T>(sql, parameters, columnsResult, 0);
sql = AppendSelect<T2>(sql, parameters, columnsResult, 1);
if (sql.Trim().First()==',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
#endregion
@ -973,7 +977,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -983,6 +987,10 @@ namespace SqlSugar
sql = AppendSelect<T>(sql, parameters, columnsResult, 0);
sql = AppendSelect<T2>(sql, parameters, columnsResult, 1);
sql = AppendSelect<T3>(sql, parameters, columnsResult, 2);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
@ -1584,7 +1592,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -1595,6 +1603,10 @@ namespace SqlSugar
sql = AppendSelect<T2>(sql, parameters, columnsResult, 1);
sql = AppendSelect<T3>(sql, parameters, columnsResult, 2);
sql = AppendSelect<T4>(sql, parameters, columnsResult, 3);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
@ -2334,7 +2346,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -2346,6 +2358,10 @@ namespace SqlSugar
sql = AppendSelect<T3>(sql, parameters, columnsResult, 2);
sql = AppendSelect<T4>(sql, parameters, columnsResult, 3);
sql = AppendSelect<T5>(sql, parameters, columnsResult, 4);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}

30
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs

@ -316,7 +316,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -329,6 +329,10 @@ namespace SqlSugar
sql = AppendSelect<T4>(sql, parameters, columnsResult, 3);
sql = AppendSelect<T5>(sql, parameters, columnsResult, 4);
sql = AppendSelect<T6>(sql, parameters, columnsResult, 5);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
#endregion
@ -1044,7 +1048,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -1058,6 +1062,10 @@ namespace SqlSugar
sql = AppendSelect<T5>(sql, parameters, columnsResult, 4);
sql = AppendSelect<T6>(sql, parameters, columnsResult, 5);
sql = AppendSelect<T7>(sql, parameters, columnsResult, 6);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
@ -1779,7 +1787,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -1794,6 +1802,10 @@ namespace SqlSugar
sql = AppendSelect<T6>(sql, parameters, columnsResult, 5);
sql = AppendSelect<T7>(sql, parameters, columnsResult, 6);
sql = AppendSelect<T8>(sql, parameters, columnsResult, 7);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
@ -2428,7 +2440,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -2444,6 +2456,10 @@ namespace SqlSugar
sql = AppendSelect<T7>(sql, parameters, columnsResult, 6);
sql = AppendSelect<T8>(sql, parameters, columnsResult, 7);
sql = AppendSelect<T9>(sql, parameters, columnsResult, 8);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
@ -3114,7 +3130,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -3131,6 +3147,10 @@ namespace SqlSugar
sql = AppendSelect<T8>(sql, parameters, columnsResult, 7);
sql = AppendSelect<T9>(sql, parameters, columnsResult, 8);
sql = AppendSelect<T10>(sql, parameters, columnsResult, 9);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}

12
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs

@ -306,7 +306,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -324,6 +324,10 @@ namespace SqlSugar
sql = AppendSelect<T9>(sql, parameters, columnsResult, 8);
sql = AppendSelect<T10>(sql, parameters, columnsResult, 9);
sql = AppendSelect<T11>(sql, parameters, columnsResult, 10);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
public ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, T2, TResult>> expression)
@ -895,7 +899,7 @@ namespace SqlSugar
var sql = clone.QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
sql = " ";
}
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
@ -914,6 +918,10 @@ namespace SqlSugar
sql = AppendSelect<T10>(sql, parameters, columnsResult, 9);
sql = AppendSelect <T11>(sql, parameters, columnsResult, 10);
sql = AppendSelect<T12>(sql, parameters, columnsResult, 11);
if (sql.Trim().First() == ',')
{
sql = sql.TrimStart(' ').TrimStart(',');
}
return this.Select<TResult>(sql);
}
public ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, T2, TResult>> expression)

4
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs

@ -153,11 +153,11 @@ namespace SqlSugar
}
public void InitMappingInfo(Type type)
{
string cacheKey = "Context.InitAttributeMappingTables" + type.FullName;
string cacheKey = "Context.InitAttributeMappingTables" + type.FullName+this.Context?.CurrentConnectionConfig?.ConfigId;
var entityInfo = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate<EntityInfo>(cacheKey,
() =>
{
var result = this.Context.EntityMaintenance.GetEntityInfo(type);
var result = this.Context.EntityMaintenance.GetEntityInfoWithAttr(type);
return result;
});
//var copyObj = CopyEntityInfo(entityInfo);

Loading…
Cancel
Save