mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Update Core
This commit is contained in:
@@ -323,28 +323,45 @@ namespace SqlSugar
|
|||||||
var navList = selector(this.Context.Queryable<object>().AS(navEntityInfo.DbTableName).AddParameters(sqlObj.Parameters).Where(conditionalModels).WhereIF(sqlObj.WhereString.HasValue(), sqlObj.WhereString).Select(sqlObj.SelectString).OrderByIF(sqlObj.OrderByString.HasValue(), sqlObj.OrderByString));
|
var navList = selector(this.Context.Queryable<object>().AS(navEntityInfo.DbTableName).AddParameters(sqlObj.Parameters).Where(conditionalModels).WhereIF(sqlObj.WhereString.HasValue(), sqlObj.WhereString).Select(sqlObj.SelectString).OrderByIF(sqlObj.OrderByString.HasValue(), sqlObj.OrderByString));
|
||||||
if (navList.HasValue())
|
if (navList.HasValue())
|
||||||
{
|
{
|
||||||
foreach (var item in list)
|
//var setValue = navList
|
||||||
|
// .Where(x => navColumn.PropertyInfo.GetValue(x).ObjToString() == listItemPkColumn.PropertyInfo.GetValue(item).ObjToString()).ToList();
|
||||||
|
var GroupQuery = (from l in list
|
||||||
|
join n in navList
|
||||||
|
on listItemPkColumn.PropertyInfo.GetValue(l).ObjToString()
|
||||||
|
equals navColumn.PropertyInfo.GetValue(n).ObjToString()
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
l,
|
||||||
|
n
|
||||||
|
}).GroupBy(it=>it.l).ToList();
|
||||||
|
foreach (var item in GroupQuery)
|
||||||
{
|
{
|
||||||
var setValue = navList
|
|
||||||
.Where(x => navColumn.PropertyInfo.GetValue(x).ObjToString() == listItemPkColumn.PropertyInfo.GetValue(item).ObjToString()).ToList();
|
|
||||||
|
|
||||||
if (sqlObj.MappingExpressions.HasValue())
|
if (sqlObj.MappingExpressions.HasValue())
|
||||||
{
|
{
|
||||||
MappingFieldsHelper<T> helper = new MappingFieldsHelper<T>();
|
MappingFieldsHelper<T> helper = new MappingFieldsHelper<T>();
|
||||||
helper.NavEntity = navEntityInfo;
|
helper.NavEntity = navEntityInfo;
|
||||||
helper.Context = this.Context;
|
helper.Context = this.Context;
|
||||||
helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||||
helper.SetChildList(navObjectNameColumnInfo, item,setValue,sqlObj.MappingExpressions);
|
helper.SetChildList(navObjectNameColumnInfo, item.Key,item.Select(it=>it.n).ToList(),sqlObj.MappingExpressions);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
var instance = Activator.CreateInstance(navObjectNamePropety.PropertyType, true);
|
var instance = Activator.CreateInstance(navObjectNamePropety.PropertyType, true);
|
||||||
var ilist = instance as IList;
|
var ilist = instance as IList;
|
||||||
foreach (var value in setValue)
|
foreach (var value in item.Select(it => it.n).ToList())
|
||||||
{
|
{
|
||||||
ilist.Add(value);
|
ilist.Add(value);
|
||||||
}
|
}
|
||||||
|
navObjectNamePropety.SetValue(item.Key, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
if (navObjectNamePropety.GetValue(item) == null)
|
||||||
|
{
|
||||||
|
var instance = Activator.CreateInstance(navObjectNamePropety.PropertyType, true);
|
||||||
navObjectNamePropety.SetValue(item, instance);
|
navObjectNamePropety.SetValue(item, instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2122,10 +2122,10 @@ namespace SqlSugar
|
|||||||
this.Context.MappingTables = oldMapping;
|
this.Context.MappingTables = oldMapping;
|
||||||
return await this.Clone().ToPageListAsync(pageIndex, pageSize);
|
return await this.Clone().ToPageListAsync(pageIndex, pageSize);
|
||||||
}
|
}
|
||||||
public Task<List<T>> ToPageListAsync(int pageNumber, int pageSize, RefAsync<int> totalNumber, RefAsync<int> totalPage)
|
public async Task<List<T>> ToPageListAsync(int pageNumber, int pageSize, RefAsync<int> totalNumber, RefAsync<int> totalPage)
|
||||||
{
|
{
|
||||||
var result = ToPageListAsync(pageNumber, pageSize, totalNumber);
|
var result =await ToPageListAsync(pageNumber, pageSize, totalNumber);
|
||||||
totalPage.Value = (totalNumber + pageSize - 1) / pageSize;
|
totalPage.Value = (totalNumber.Value + pageSize - 1) / pageSize;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public async Task<string> ToJsonAsync()
|
public async Task<string> ToJsonAsync()
|
||||||
|
Reference in New Issue
Block a user