update

28810
2020-04-06 20:08:27 +08:00
parent 1e1605ce3d
commit 5a716052db

@@ -19,7 +19,6 @@ IncludeMany 贪婪加载集合的导航属性,其实是分两次查询,在 T
```csharp
Select<Tag>().IncludeMany(a => a.Songs).ToList();
//这是 ManyToMany 关系的贪婪加载
```
IncludeMany 有第二个参数,可以进行二次查询前的修饰工作。
@@ -29,11 +28,11 @@ Select<Tag>().IncludeMany(a => a.Songs,
then => then.Where(song => song.User == "admin")).ToList();
```
然后,其实在 then 那里,还可以继续进行向下 Include/IncludeMany。只要你喜欢向下 100 层都没问题。
其实在 then 那里,还可以继续进行向下 Include/IncludeMany。只要你喜欢向下 100 层都没问题。
## 3、变异
变异的 IncludeMany 使用的集合属性未配置导航,也可以贪婪加载。
没有配置导航关系,也可以贪婪加载。
```csharp
Select<Tag>().IncludeMany(a => a.TestManys.Where(b => b.TagId == a.Id));
@@ -45,7 +44,7 @@ Select<Tag>().IncludeMany(a => a.TestManys.Where(b => b.TagId == a.Id));
Select<Tag>().IncludeMany(a => a.TestManys.Take(10));
```
设置子集合返回部分字段,避免子集合字段过多的问题。
子集合返回部分字段,避免字段过多的问题。
```csharp
Select<Tag>().IncludeMany(a => a.TestManys.Select(b => new TestMany { Title = b.Title ... }));
@@ -53,16 +52,12 @@ Select<Tag>().IncludeMany(a => a.TestManys.Select(b => new TestMany { Title = b.
## 4、IncludeMany 扩展方法
前面介绍 ISelect 中进行贪婪加载集合属性数据,并且只能使用 IncludeMany + ToList() 组合(不能使用指定字段查询)。
当主数据已存在内存中,子数据怎么加载?所以我们增加了 List\<T\> 扩展方法,示例如下:
```csharp
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(fsql, a => a.Tags);
```
这个扩展方法IncludeMany参数基本一致除了需要额外传递 IFreeSql功能也一致包括前面提到的变异
## 5、IncludeMany 两种方式对比
方式一IncludeMany 扩展方法):