Update Core

This commit is contained in:
skx 2021-01-18 00:52:12 +08:00
parent 7df4d3d2a6
commit 019a919f44
3 changed files with 23 additions and 12 deletions

View File

@ -1373,15 +1373,7 @@ namespace SqlSugar
}
protected ISugarQueryable<T> _As(string tableName, string entityName)
{
IsAs = true;
OldMappingTableList = this.Context.MappingTables;
this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
if (this.Context.MappingTables.Any(it => it.EntityName == entityName))
{
this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
}
this.Context.MappingTables.Add(entityName, tableName);
this.QueryableMappingTableList = this.Context.MappingTables;
this.QueryBuilder.AsTables.Add(entityName, tableName);
return this;
}
protected void _Filter(string FilterName, bool isDisabledGobalFilter)
@ -2048,6 +2040,7 @@ namespace SqlSugar
asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos;
asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex;
asyncQueryableBuilder.IgnoreColumns = this.QueryBuilder.IgnoreColumns;
asyncQueryableBuilder.AsTables = this.QueryBuilder.AsTables;
}
protected int SetCacheTime(int cacheDurationInSeconds)
{

View File

@ -114,6 +114,7 @@ namespace SqlSugar
#endregion
#region Sql Template
public Dictionary<string, string> AsTables=new Dictionary<string, string>();
public virtual string SqlTemplate
{
get
@ -357,10 +358,22 @@ namespace SqlSugar
public virtual string ToJoinString(JoinQueryInfo joinInfo)
{
var name = joinInfo.TableName;
if (this.AsTables.Any())
{
if (this.Context.MappingTables != null && this.Context.MappingTables.Any(it => it.DbTableName == name))
{
name = this.Context.MappingTables.First(it => it.DbTableName == name).EntityName;
}
if (this.AsTables.Any(it => it.Key == name))
{
name = this.AsTables.First(it => it.Key == name).Value;
}
}
return string.Format(
this.JoinTemplate,
joinInfo.JoinType.ToString() + UtilConstants.Space,
Builder.GetTranslationTableName(joinInfo.TableName) + UtilConstants.Space,
Builder.GetTranslationTableName(name) + UtilConstants.Space,
joinInfo.ShortName + UtilConstants.Space + (TableWithString == SqlWith.Null ? " " : TableWithString),
joinInfo.JoinWhere);
}
@ -484,7 +497,12 @@ namespace SqlSugar
{
get
{
var result = Builder.GetTranslationTableName(EntityName);
var name = EntityName;
if (this.AsTables.Any(it=>it.Key==EntityName))
{
name = this.AsTables.FirstOrDefault(it => it.Key == EntityName).Value;
}
var result = Builder.GetTranslationTableName(name);
result += UtilConstants.Space;
if (result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable"))
{

View File

@ -31,7 +31,7 @@ namespace SqlSugar
public virtual string GetTranslationTableName(string name)
{
Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
if (name.IsContainsIn("(", ")", SqlTranslationLeft)&&name!= "Dictionary`2")
if (!name.Contains("<>f__AnonymousType") &&name.IsContainsIn("(", ")", SqlTranslationLeft)&&name!= "Dictionary`2")
{
return name;
}