Table of Contents

Dapper.Shadow.Core

  • ShadowSql.Core的Dapper扩展
  • 用于执行ShadowSql.Core拼接的sql
  • 支持多种数据库,包括MsSql,MySql,Oracle,Sqlite,Postgres等,可扩展其他数据库方言的支持
  • Nuget包名: ShadowSql.Dapper.Core
  • 精简版

1. 读取一张表

    var table = EmptyTable.Use("Students");        
    var count = await table.CountAsync(Executor);
    var select = new TableSelect(table);
    var students = await select.GetAsync<Student>(Executor);

2. 分页查询

    var table = new StudentTable("Students");
    var query = new TableSqlQuery(table)
        .Where(table.Age.GreaterEqualValue(9));
    var count = await query.CountAsync(Executor);
    var cursor = new TableCursor(query)
        .Desc(table.Id)
        .Skip(1)
        .Take(10);
    var select = new TableSelect(cursor);
    var students = await select.GetAsync<Student>(Executor);

3. 删除

    var table = new StudentTable();
    var query = new TableSqlQuery(table)
        .Where(table.Age.LessValue(7));
    var delete = new TableDelete(table, query.Filter);
    var result = await Executor.ExecuteAsync(delete);

4. 更新

    var table = new StudentTable();
    var query = new TableSqlQuery(table)
        .Where(table.Age.LessValue(7));
    var update = new TableUpdate(table, query.Filter)
        .Set(table.ClassId.AssignValue(1));
    var result = await SqliteExecutor.ExecuteAsync(update);

5. 插入

    var table = _db.From("Students")
        .AddColums(_name, _age);
    var insert = new SingleInsert(table)
        .Insert(_name.InsertValue("张三"))
        .Insert(_age.InsertValue(11));
    var result = await insert.ExecuteAsync(Executor);