mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 优化 内部代码 GeTableRef
This commit is contained in:
@ -547,10 +547,8 @@ public static partial class FreeSqlGlobalExtensions
|
||||
{
|
||||
var select = that as Select1Provider<T1>;
|
||||
var tb = select._tables[0].Table;
|
||||
var navs = tb.Properties.Select(a => tb.GetTableRef(a.Key, false))
|
||||
.Where(a => a != null &&
|
||||
a.RefType == FreeSql.Internal.Model.TableRefType.OneToMany &&
|
||||
a.RefEntityType == tb.Type).ToArray();
|
||||
var navs = tb.GetAllTableRef().Where(a => a.Value.Exception == null).Select(a => a.Value)
|
||||
.Where(a => a.RefType == FreeSql.Internal.Model.TableRefType.OneToMany && a.RefEntityType == tb.Type).ToArray();
|
||||
|
||||
var list = select.ToList();
|
||||
if (navs.Length != 1) return list;
|
||||
@ -570,10 +568,8 @@ public static partial class FreeSqlGlobalExtensions
|
||||
{
|
||||
var select = that as Select1Provider<T1>;
|
||||
var tb = select._tables[0].Table;
|
||||
var navs = tb.Properties.Select(a => tb.GetTableRef(a.Key, false))
|
||||
.Where(a => a != null &&
|
||||
a.RefType == FreeSql.Internal.Model.TableRefType.OneToMany &&
|
||||
a.RefEntityType == tb.Type).ToArray();
|
||||
var navs = tb.GetAllTableRef().Where(a => a.Value.Exception == null).Select(a => a.Value)
|
||||
.Where(a => a.RefType == FreeSql.Internal.Model.TableRefType.OneToMany && a.RefEntityType == tb.Type).ToArray();
|
||||
|
||||
var list = await select.ToListAsync(false, cancellationToken);
|
||||
if (navs.Length != 1) return list;
|
||||
@ -614,10 +610,8 @@ public static partial class FreeSqlGlobalExtensions
|
||||
var select = that as Select1Provider<T1>;
|
||||
select._is_AsTreeCte = true;
|
||||
var tb = select._tables[0].Table;
|
||||
var navs = tb.Properties.Select(a => tb.GetTableRef(a.Key, false))
|
||||
.Where(a => a != null &&
|
||||
a.RefType == FreeSql.Internal.Model.TableRefType.OneToMany &&
|
||||
a.RefEntityType == tb.Type).ToArray();
|
||||
var navs = tb.GetAllTableRef().Where(a => a.Value.Exception == null).Select(a => a.Value)
|
||||
.Where(a => a.RefType == FreeSql.Internal.Model.TableRefType.OneToMany && a.RefEntityType == tb.Type).ToArray();
|
||||
|
||||
if (navs.Length != 1) throw new ArgumentException(CoreStrings.Entity_NotParentChild_Relationship(tb.Type.FullName));
|
||||
var tbref = navs[0];
|
||||
|
@ -198,10 +198,11 @@ namespace FreeSql.Internal
|
||||
}
|
||||
if (_tables?.Count > 1)
|
||||
{ //如果下级导航属性被 Include 过,则将他们也查询出来
|
||||
foreach (var memProp in tb.Properties.Values)
|
||||
foreach (var tr in tb.GetAllTableRef())
|
||||
{
|
||||
var memtbref = tb.GetTableRef(memProp.Name, false);
|
||||
if (memtbref == null) continue;
|
||||
var memtbref = tr.Value;
|
||||
if (memtbref.Exception != null) continue;
|
||||
if (tb.Properties.TryGetValue(tr.Key, out var memProp) == false) continue;
|
||||
switch (memtbref.RefType)
|
||||
{
|
||||
case TableRefType.ManyToMany:
|
||||
|
@ -940,16 +940,16 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
}
|
||||
var parentNavs = new List<string>();
|
||||
foreach (var navProp in tbref2.Properties)
|
||||
foreach (var tr2 in tbref2.GetAllTableRef())
|
||||
{
|
||||
if (tbref2.ColumnsByCs.ContainsKey(navProp.Key)) continue;
|
||||
if (tbref2.ColumnsByCsIgnore.ContainsKey(navProp.Key)) continue;
|
||||
var tr2ref = tbref2.GetTableRef(navProp.Key, false);
|
||||
if (tr2ref == null) continue;
|
||||
var tr2ref = tr2.Value;
|
||||
if (tr2ref.Exception != null) continue;
|
||||
if (tbref2.ColumnsByCs.ContainsKey(tr2.Key)) continue;
|
||||
if (tbref2.ColumnsByCsIgnore.ContainsKey(tr2.Key)) continue;
|
||||
if (tr2ref.RefType != TableRefType.ManyToOne) continue;
|
||||
if (tr2ref.RefEntityType != tb.Type) continue;
|
||||
if (string.Join(",", tr2ref.Columns.Select(a => a.CsName).OrderBy(a => a)) != string.Join(",", tbref.RefColumns.Select(a => a.CsName).OrderBy(a => a))) continue; //- 修复 IncludeMany 只填充子属性中双向关系的 ManyToOne 对象值;防止把 ManyToOne 多个相同类型的导航属性值都填充了
|
||||
parentNavs.Add(navProp.Key);
|
||||
parentNavs.Add(tr2.Key);
|
||||
}
|
||||
foreach (var nav in subList)
|
||||
{
|
||||
@ -1366,16 +1366,16 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var dicSubList = subList.ToDictionary(a => EntityUtilExtensions.GetEntityValueWithPropertyName(_orm, tbref.RefEntityType, a, tbref.RefColumns[0].CsName)?.ToString(), a => a);
|
||||
|
||||
var parentNavs = new List<string>();
|
||||
foreach (var navProp in tbref2.Properties)
|
||||
foreach (var tr2 in tbref2.GetAllTableRef())
|
||||
{
|
||||
if (tbref2.ColumnsByCs.ContainsKey(navProp.Key)) continue;
|
||||
if (tbref2.ColumnsByCsIgnore.ContainsKey(navProp.Key)) continue;
|
||||
var tr2ref = tbref2.GetTableRef(navProp.Key, false);
|
||||
if (tr2ref == null) continue;
|
||||
var tr2ref = tr2.Value;
|
||||
if (tr2ref.Exception != null) continue;
|
||||
if (tbref2.ColumnsByCs.ContainsKey(tr2.Key)) continue;
|
||||
if (tbref2.ColumnsByCsIgnore.ContainsKey(tr2.Key)) continue;
|
||||
if (tr2ref.RefType != TableRefType.ManyToOne) continue;
|
||||
if (tr2ref.RefEntityType != tb.Type) continue;
|
||||
if (string.Join(",", tr2ref.Columns.Select(a => a.CsName).OrderBy(a => a)) != string.Join(",", tbref.RefColumns.Select(a => a.CsName).OrderBy(a => a))) continue; //- 修复 IncludeMany 只填充子属性中双向关系的 ManyToOne 对象值;防止把 ManyToOne 多个相同类型的导航属性值都填充了
|
||||
parentNavs.Add(navProp.Key);
|
||||
parentNavs.Add(tr2.Key);
|
||||
}
|
||||
for (var y = 0; y < list.Count; y++)
|
||||
{
|
||||
|
Reference in New Issue
Block a user