mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 指定导航属性查询时,如果下级导航属性被 Include 过,则将他们也查询出来;
This commit is contained in:
parent
cdbc6d5a04
commit
09d7623b1b
@ -130,6 +130,13 @@
|
||||
清空状态数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||
<summary>
|
||||
根据 lambda 条件删除数据
|
||||
</summary>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
@ -525,5 +532,14 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -512,6 +512,20 @@ namespace FreeSql.Tests.MySql
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?bname", sql);
|
||||
query.ToList();
|
||||
|
||||
sql = select.ToSql(a => a.Type.Parent);
|
||||
Assert.Equal(@"SELECT a__Type__Parent.`Id` as1, a__Type__Parent.`Name` as2
|
||||
FROM `tb_topic` a
|
||||
LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TypeGuid`
|
||||
LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type.`ParentId`", sql);
|
||||
var ccdata1 = select.ToList(a => a.Type.Parent);
|
||||
|
||||
sql = select.Include(a => a.Type.Parent).ToSql(a => a.Type);
|
||||
Assert.Equal(@"SELECT a__Type.`Guid` as1, a__Type.`ParentId` as2, a__Type.`Name` as3, a__Type__Parent.`Id` as4, a__Type__Parent.`Name` as5
|
||||
FROM `tb_topic` a
|
||||
LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TypeGuid`
|
||||
LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type.`ParentId`", sql);
|
||||
var ccdata2 = select.Include(a => a.Type.Parent).ToList(a => a.Type);
|
||||
}
|
||||
[Fact]
|
||||
public void InnerJoin()
|
||||
|
@ -112,6 +112,30 @@ namespace FreeSql.Internal
|
||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||
parent.Childs.Add(child);
|
||||
}
|
||||
if (_tables.Count > 1) { //如果下级导航属性被 Include 过,则将他们也查询出来
|
||||
foreach (var memProp in tb.Properties.Values)
|
||||
{
|
||||
var memtbref = tb.GetTableRef(memProp.Name, false);
|
||||
if (memtbref == null) continue;
|
||||
switch (memtbref.RefType)
|
||||
{
|
||||
case TableRefType.ManyToMany:
|
||||
case TableRefType.OneToMany:
|
||||
continue;
|
||||
}
|
||||
if (_tables.Any(a => a.Alias == $"{map.First().Table.Alias}__{memProp.Name}") == false) continue;
|
||||
|
||||
var child = new ReadAnonymousTypeInfo
|
||||
{
|
||||
Property = memProp,
|
||||
CsName = memProp.Name,
|
||||
CsType = memProp.PropertyType,
|
||||
MapType = memProp.PropertyType
|
||||
};
|
||||
parent.Childs.Add(child);
|
||||
ReadAnonymousField(_tables, field, child, ref index, Expression.MakeMemberAccess(exp, memProp), grouping, whereCascadeExpression, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user