Browse Source

Synchronization code

pull/29/head
sunkaixuan 2 years ago
parent
commit
dcd7bd7e7e
  1. 4
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs
  2. 24
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs
  3. 23
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs

4
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs

@ -326,6 +326,10 @@ namespace SqlSugar
{ {
navPkColumn = navEntityInfo.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault(); navPkColumn = navEntityInfo.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault();
} }
if (navPkColumn == null && navType.FullName.IsCollectionsList())
{
Check.ExceptionEasy($"{navObjectNamePropety.Name} type error ", $"一对一不能是List对象 {navObjectNamePropety.Name} ");
}
var ids = list.Select(it => it.GetType().GetProperty(navObjectNameColumnInfo.Navigat.Name).GetValue(it)).Select(it => it == null ? "null" : it).Distinct().ToList(); var ids = list.Select(it => it.GetType().GetProperty(navObjectNameColumnInfo.Navigat.Name).GetValue(it)).Select(it => it == null ? "null" : it).Distinct().ToList();
List<IConditionalModel> conditionalModels = new List<IConditionalModel>(); List<IConditionalModel> conditionalModels = new List<IConditionalModel>();
conditionalModels.Add((new ConditionalModel() conditionalModels.Add((new ConditionalModel()

24
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs

@ -942,9 +942,19 @@ namespace SqlSugar
{ {
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )"; this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )";
} }
else if (this.QueryBuilder.IsSqlQuery && this.QueryBuilder.AsTables.First().Value.ObjToString().StartsWith("("))
{
var tableName = this.QueryBuilder.AsTables.First().Value;
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + tableName + ")" + this.QueryBuilder.TableShortName;
}
else else
{ {
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + ")"; var tableName = this.QueryBuilder.AsTables.First().Value;
if (tableName != null && Regex.IsMatch(tableName, @"^\w+$"))
{
tableName = SqlBuilder.GetTranslationTableName(tableName);
}
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + tableName + ")";
} }
this.QueryBuilder.SelectValue = this.QueryBuilder.TableShortName + ".*"; this.QueryBuilder.SelectValue = this.QueryBuilder.TableShortName + ".*";
} }
@ -1575,5 +1585,17 @@ namespace SqlSugar
return this.Context.Ado.SqlQuery<Type>(sql,parameters); return this.Context.Ado.SqlQuery<Type>(sql,parameters);
} }
#endregion #endregion
#region Bool
private bool MasterHasWhereFirstJoin()
{
return this.QueryBuilder.JoinIndex == 0 &&
this.QueryBuilder.IsSqlQuery == false &&
!this.QueryBuilder.AsTables.Any() &&
this.QueryBuilder.IsSingle() &&
this.QueryBuilder.WhereInfos.Any();
}
#endregion
} }
} }

23
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -116,6 +116,11 @@ namespace SqlSugar
} }
public ISugarQueryable<T, T2> LeftJoin<T2>(Expression<Func<T, T2, bool>> joinExpression) public ISugarQueryable<T, T2> LeftJoin<T2>(Expression<Func<T, T2, bool>> joinExpression)
{ {
if (MasterHasWhereFirstJoin())
{
return this.MergeTable().LeftJoin<T2>(joinExpression);
}
this.Context.InitMappingInfo<T2>(); this.Context.InitMappingInfo<T2>();
var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig); var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig);
result.SqlBuilder = this.SqlBuilder; result.SqlBuilder = this.SqlBuilder;
@ -126,6 +131,11 @@ namespace SqlSugar
} }
public ISugarQueryable<T, T2> FullJoin<T2>(Expression<Func<T, T2, bool>> joinExpression) public ISugarQueryable<T, T2> FullJoin<T2>(Expression<Func<T, T2, bool>> joinExpression)
{ {
if (MasterHasWhereFirstJoin())
{
return this.MergeTable().FullJoin<T2>(joinExpression);
}
this.Context.InitMappingInfo<T2>(); this.Context.InitMappingInfo<T2>();
var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig); var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig);
result.SqlBuilder = this.SqlBuilder; result.SqlBuilder = this.SqlBuilder;
@ -135,6 +145,12 @@ namespace SqlSugar
} }
public ISugarQueryable<T, T2> RightJoin<T2>(Expression<Func<T, T2, bool>> joinExpression) public ISugarQueryable<T, T2> RightJoin<T2>(Expression<Func<T, T2, bool>> joinExpression)
{ {
if (MasterHasWhereFirstJoin())
{
return this.MergeTable().RightJoin<T2>(joinExpression);
}
this.Context.InitMappingInfo<T2>(); this.Context.InitMappingInfo<T2>();
var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig); var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig);
result.SqlBuilder = this.SqlBuilder; result.SqlBuilder = this.SqlBuilder;
@ -145,6 +161,12 @@ namespace SqlSugar
public ISugarQueryable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpression) public ISugarQueryable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpression)
{ {
if (MasterHasWhereFirstJoin())
{
return this.MergeTable().InnerJoin<T2>(joinExpression);
}
this.Context.InitMappingInfo<T2>(); this.Context.InitMappingInfo<T2>();
var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig); var result = InstanceFactory.GetQueryable<T, T2>(this.Context.CurrentConnectionConfig);
result.SqlBuilder = this.SqlBuilder; result.SqlBuilder = this.SqlBuilder;
@ -152,6 +174,7 @@ namespace SqlSugar
result.QueryBuilder.JoinQueryInfos.Add(GetJoinInfo(joinExpression, JoinType.Inner)); result.QueryBuilder.JoinQueryInfos.Add(GetJoinInfo(joinExpression, JoinType.Inner));
return result; return result;
} }
public void Clear() public void Clear()
{ {
QueryBuilder.Clear(); QueryBuilder.Clear();

2
Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs

@ -181,7 +181,7 @@ namespace SqlSugar
protected override string IsAnyTableRemarkSql { get { throw new NotSupportedException(); } } protected override string IsAnyTableRemarkSql { get { throw new NotSupportedException(); } }
protected override string RenameTableSql => "alter table 表名 {0} to {1}"; protected override string RenameTableSql => "alter table {0} to {1}";
protected override string CreateIndexSql protected override string CreateIndexSql
{ {

Loading…
Cancel
Save