Updated Lazy Loading (markdown)

AlexLEWIS
2021-09-29 11:12:15 +08:00
parent c5d4440863
commit 834f881329

@@ -1,10 +1,10 @@
[中文](%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) | **English**
FreeSql 支持导航属性延时加载即当我们需要用到的时候才进行加载读取支持1对1、多对1、1对多、多对多关系的导航属性。
FreeSql supports lazy loading of navigation properties, that is, data is loaded (read) when we need it. It supports navigation properties of _One-to-One_, _Many-to-One_, _One-to-Many_, and _Many-to-Many_ relationships.
当我们希望浏览某条订单信息的时候,才显示其对应的订单详细记录时,我们希望使用延迟加载来实现,这样不仅加快的了 读取的效率同时也避免加载不需要的数据。延迟加载通常用于foreach循环读取数据时。
When we want to query a certain order information and display its corresponding order detailed records, we hope to use lazy loading to achieve. This not only speeds up the reading speed, but also avoids loading unnecessary data. Lazy loading is usually used for _foreach loop_ queries.
那么我们在定义Model的时候需要在属性前面添加virtual关键字。如下
When we are defining the _Model_, we need to add the `virtual` keyword in front of the properties. As follows:
```csharp
public class Order {
@@ -24,9 +24,9 @@ public class OrderDetail {
}
```
> The lazy loading function is turned off by default. When using this function, please turn it on at the place of declaration.
> The Lazy Loading function is _turn-off_ by default. When using this function, please turn it on at the place of declaration.
> Lazy loading function depends on FreeSql.Extensions.LazyLoading package, please go to NuGet to download.
> Lazy loading function depends on _FreeSql.Extensions.LazyLoading_ package, please go to NuGet to download.
```csharp
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
@@ -55,7 +55,7 @@ FROM `OrderDetail` a
WHERE (a.`OrderId` = 1)
```
FreeSql lazy loading supports navigation properties of One-to-One, Many-to-One, One-to-Many, and Many-to-Many relationships. The first three are similar. We separately introduce the Many-to-Many relationship.
FreeSql lazy loading supports navigation properties of _One-to-One_, _Many-to-One_, _One-to-Many_, and _Many-to-Many_ relationships. The first three are similar. We separately introduce the _Many-to-Many_ relationship.
## Many-to-Many Lazy Loading
@@ -90,7 +90,7 @@ public partial class Tag {
}
```
As above, there are three tables: Song, Tag, and their relationship table.
As above, there are three tables: **Song**, **Tag**, and their relationship table.
```csharp
var songs = fsql.Select<Song>().Limit(10).ToList(); //Take 10 pieces of song