Navigate.Dynamic multi-level BUG

This commit is contained in:
sunkaixuan
2022-05-05 09:13:59 +08:00
parent 4a58971fd3
commit 1abf16f817
5 changed files with 32 additions and 28 deletions

View File

@@ -14,7 +14,10 @@ namespace OrmTest
var list=db.Queryable<StudentA>()
.Includes(it => it.Books.Where(z=>z.BookId==1)
.MappingField(z=>z.studenId,()=>it.StudentId)
.MappingField(z => z.BookId, () => it.StudentId).ToList())
.MappingField(z => z.BookId, () => it.StudentId).ToList()
, c=>c.bookChilds
.MappingField(z=>z.BookId,()=>c.BookId).ToList())
.ToList();
var list2 = db.Queryable<StudentA>().ToList();
@@ -58,6 +61,8 @@ namespace OrmTest
[SugarColumn(ColumnName = "Name")]
public string Names { get; set; }
public int studenId { get; set; }
[Navigate(NavigateType.Dynamic,null)]
public List<BookA> bookChilds { get; set; }
}
}
}

View File

@@ -29,7 +29,7 @@ namespace SqlSugar
return mappingFields;
}
public List<IConditionalModel> GetMppingSql(List<T> list, List<MappingFieldsExpression> mappingFieldsExpressions)
public List<IConditionalModel> GetMppingSql(List<object> list, List<MappingFieldsExpression> mappingFieldsExpressions)
{
List<IConditionalModel> conditionalModels = new List<IConditionalModel>();
foreach (var model in list)
@@ -141,9 +141,26 @@ namespace SqlSugar
{
item.LeftEntityColumn = this.NavEntity.Columns.FirstOrDefault(it => it.PropertyName == leftName);
}
if (item.RightEntityColumn == null)
if (item.RightEntityColumn == null && this.Context != null)
{
item.RightEntityColumn = this.RootEntity.Columns.FirstOrDefault(it => it.PropertyName == rightName);
if (item.RightColumnExpression is LambdaExpression)
{
var body=(item.RightColumnExpression as LambdaExpression).Body;
if (body is UnaryExpression)
{
body = ((UnaryExpression)body).Operand;
}
if (body is MemberExpression)
{
var exp=(body as MemberExpression).Expression;
if (exp.NodeType == ExpressionType.Parameter)
{
item.RightEntityColumn =this.Context.EntityMaintenance.GetEntityInfo(exp.Type).Columns.FirstOrDefault(it => it.PropertyName == rightName);
}
}
}
if (item.RightEntityColumn==null)
item.RightEntityColumn = this.RootEntity.Columns.FirstOrDefault(it => it.PropertyName == rightName);
}
}

View File

@@ -243,6 +243,7 @@ namespace SqlSugar
if (sql.MappingExpressions.HasValue())
{
MappingFieldsHelper<T> helper = new MappingFieldsHelper<T>();
helper.Context = this.Context;
helper.NavEntity = bEntityInfo;
helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
helper.SetChildList(navObjectNameColumnInfo, listItem, ilist.Cast<object>().ToList(), sql.MappingExpressions);
@@ -319,6 +320,7 @@ namespace SqlSugar
{
MappingFieldsHelper<T> helper = new MappingFieldsHelper<T>();
helper.NavEntity = navEntityInfo;
helper.Context = this.Context;
helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
helper.SetChildList(navObjectNameColumnInfo, item,setValue,sqlObj.MappingExpressions);
}
@@ -350,7 +352,7 @@ namespace SqlSugar
helper.Context = this.Context;
helper.NavEntity = navEntityInfo;
helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var whereSql = helper.GetMppingSql(RootList,sqlObj.MappingExpressions);
var whereSql = helper.GetMppingSql(list, sqlObj.MappingExpressions);
var navList = selector(this.Context.Queryable<object>().AS(navEntityInfo.DbTableName).AddParameters(sqlObj.Parameters).Where(whereSql,true).WhereIF(sqlObj.WhereString.HasValue(), sqlObj.WhereString).Select(sqlObj.SelectString).OrderByIF(sqlObj.OrderByString.HasValue(), sqlObj.OrderByString));
if (navList.HasValue())
{

View File

@@ -1448,7 +1448,7 @@ namespace SqlSugar
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled2))
}
};
var conditionals=fieldsHelper.GetMppingSql(list, mappings);
var conditionals=fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
if (queryableContext.TempChildLists == null)
queryableContext.TempChildLists = new Dictionary<string, object>();
if (list != null && queryableContext.TempChildLists.ContainsKey(key))
@@ -1542,7 +1542,7 @@ namespace SqlSugar
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled2))
}
};
var conditionals = fieldsHelper.GetMppingSql(list, mappings);
var conditionals = fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
if (queryableContext.TempChildLists == null)
queryableContext.TempChildLists = new Dictionary<string, object>();
if (list != null && queryableContext.TempChildLists.ContainsKey(key))

View File

@@ -431,27 +431,7 @@
<None Include="packages.config" />
<None Include="SqlSugar.nuspec" />
</ItemGroup>
<ItemGroup>
<Folder Include="Abstract\AdoProvider\Abstract\AdoProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\AopProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\CacheProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\CodeFirstProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\DbBindProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\DbFirstProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\DbMaintenanceProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\DeleteProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\EntityMaintenance\" />
<Folder Include="Abstract\AdoProvider\Abstract\ExpressionableProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\FastestProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\FilterProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\InsertableProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\QueryableProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\Reportable\" />
<Folder Include="Abstract\AdoProvider\Abstract\SaveableProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\SqlBuilderProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\SugarProvider\" />
<Folder Include="Abstract\AdoProvider\Abstract\UpdateProvider\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.