IFreeSql fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
.UseAutoSyncStructure(true) //自动同步实体结构到数据库
.Build();
[Table(Name = "tb_topic")]
class Topic {
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int Clicks { get; set; }
public int TestTypeInfoGuid { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
ISelect<Topic> select => fsql.Select<Topic>();
Page 20 data, query on page 1
var sql = select.Page(1, 20).ToSql();
///SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime`
//FROM `tb_topic` a
//LIMIT 0,20
optimization
SqlServer previous version 2012, using row_number paging;
SqlServer 2012+ version, use the latest fetch next rows paging;
Take/Limit
10 records before returning: select.Take (10) .ToList ();
Offset/Skip
Skip 10 prior to recording, return records: select.Offset (10) .ToList ();
API
method | return value | parameter | description |
---|---|---|---|
ToSql | string | Returns the SQL statement to be executed | |
ToList | List
|
Execute SQL query and returns all fields of record T1 entity, if the navigation attribute exists with query returns Count returns, there is no record of when the list 0 | |
ToList<T> | List<T> | Lambda | Execute SQL query and returns the specified record fields, Count returned when no records exist to list 0 |
ToList<T> | List<T> | string field | Executing the SQL query, returns the specified field recording field, and tuple or base type (int, string, long) receiving, recording absence Count returned list 0 |
[Page] | |||
Count | long | Record number of queries | |
Count | <this> | out long | The number of records the query returns a parameter out form |
Skip | <this> | int offset | Queries offset rows back |
Offset | <this> | int offset | Queries offset rows back |
Limit | <this> | int limit | How many data query |
Take | <this> | int limit | How many data query |
Page | <this> | int pageIndex, int pageSize | Paging |