mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-06 00:10:55 +08:00
Updated Return Data (markdown)
@@ -102,7 +102,7 @@ List<dynamic> t13 = fsql.Ado.Query<dynamic>("select * from song");
|
||||
|
||||
> Note: The entity attributes of `Ado.Query` are invalid, for example, `[Column(Name = "xxx")]` is invalid
|
||||
|
||||
## 9、WithSql
|
||||
## WithSql
|
||||
|
||||
```csharp
|
||||
fsql.Select<Topic>()
|
||||
@@ -150,27 +150,27 @@ fsql.Select<Song>().ToList(a => new { id = a.id })
|
||||
|
||||
```csharp
|
||||
fsql.Select<Song>().ToList(a => new Dto(a.id))
|
||||
//情况5:只查询 id,返回 List<Dto>
|
||||
//Case 5: Only query id and return List<Dto>
|
||||
|
||||
fsql.Select<Song>().ToList(a => new Dto(a.id) { xxx = a.ext })
|
||||
//情况6:查询 id, ext,返回 List<Dto>
|
||||
//Case 6: Query id, ext and return List<Dto>
|
||||
|
||||
fsql.Select<Song>().ToList(a => new Song(a.id))
|
||||
//情况7:查询 id,返回 List<Song>
|
||||
//Case 7: Query id and return List<Song>
|
||||
|
||||
fsql.Select<Song>().ToList(a => new Song(a.id) { xxx = a.ext })
|
||||
//情况8:查询 id, ext,返回 List<Song>
|
||||
//Case 8: Query id, ext and return List<Song>
|
||||
```
|
||||
|
||||
> All methods of GroupBy are not applicable to DTO mapping rules
|
||||
|
||||
这种映射支持单表/多表,在查询数据之前映射(不是先查询所有字段再到内存映射)
|
||||
This kind of mapping supports single table/multi-table, mapping before querying data (not to query all fields first and then to memory mapping).
|
||||
|
||||
查找规则,查找属性名,会循环内部对象 _tables(join 查询后会增长),以 主表优先查,直到查到相同的字段。
|
||||
Searching rules, searching for property names, will loop the internal object `_tables` (it will grow after join query), and check the main table first until the same field is found.
|
||||
|
||||
如:
|
||||
For example:
|
||||
|
||||
A, B, C 都有 id,Dto { id, a1, a2, b1, b2 },A.id 被映射。也可以指定 id = C.id 映射。
|
||||
Suppose A, B, and C all have id. When the queried Dto structure is: `Dto {id, a1, a2, b1, b2 }`, `A.id` is mapped. You can also specify the `id = C.id` mapping.
|
||||
|
||||
> Reminder: You can directly map a navigation property in DTO
|
||||
|
||||
@@ -179,12 +179,12 @@ A, B, C 都有 id,Dto { id, a1, a2, b1, b2 },A.id 被映射。也可以指
|
||||
| Method | Return | Parameter | Description |
|
||||
| ------------- | - | - | - |
|
||||
| ToSql | string | | Return the SQL statement to be executed |
|
||||
| ToList | List\<T1\> | | 执行SQL查询,返回 T1 实体所有字段的记录,若存在导航属性则一起查询返回,记录不存在时返回 Count 为 0 的列表 |
|
||||
| ToList\<Dto\> | List\<Dto\> | Lambda | 执行SQL查询,返回指定字段或Dto映射的记录,记录不存在时返回 Count 为 0 的列表 |
|
||||
| ToList\<T\> | List\<T\> | string field | 执行SQL查询,返回 field 指定字段的记录,并以元组或基础类型(int,string,long)接收,记录不存在时返回 Count 为 0 的列表 |
|
||||
| ToOne | T1 | | 执行SQL查询,返回 T1 实体所有字段的第一条记录,记录不存在时返回 null |
|
||||
| ToChunk | \<空\> | int size, Action\<FetchCallbackArgs\<List\<T1\>\>\> done | 执行SQL查询,分块返回数据,可减少内存开销。比如读取10万条数据,每次返回100条处理。 |
|
||||
| Any | bool | | 执行SQL查询,是否有记录 |
|
||||
| ToList | List\<T1\> | | Execute a SQL query and return the records of all the fields of the T1 entity. If there are navigation properties, they will be queried and returned together. If the record does not exist, a list with Count of 0 will be returned. |
|
||||
| ToList\<Dto\> | List\<Dto\> | Lambda | Execute SQL query, return the record of the specified field or Dto mapping, if the record does not exist, return the list with Count as 0. |
|
||||
| ToList\<T\> | List\<T\> | string field | Execute SQL query, return the record of the field specified by field, and receive it as a tuple or basic type (int, string, long). If the record does not exist, return a list with Count of 0. |
|
||||
| ToOne | T1 | | Execute SQL query and return the first record of all fields of the T1 entity, or null if the record does not exist. |
|
||||
| ToChunk | \<空\> | int size, Action\<FetchCallbackArgs\<List\<T1\>\>\> done | Execute SQL query and return data in blocks, which can reduce memory overhead. For example, if 100,000 pieces of data are read, 100 pieces of data are returned for processing each time. |
|
||||
| Any | bool | | Execute SQL query to determine whether there is a record |
|
||||
| Sum | T | Lambda | Specify a column to sum. |
|
||||
| Min | T | Lambda | Specify a column to find the minimum. |
|
||||
| Max | T | Lambda | Specify a column to find the maximum. |
|
||||
|
||||
Reference in New Issue
Block a user