基于Dapper的开源Lambda扩展,且支持分库分表自动生成实体二
程序员文章站
2022-03-19 23:37:03
LnskyDB " " " " LnskyDB是基于Dapper的Lambda扩展,支持按时间分库分表,也可以自定义分库分表方法.而且可以T4生成实体类免去手写实体类的烦恼. 文档地址: https://liningit.github.io/LnskyDB/ 开源地址: https://github ......
lnskydb
lnskydb是基于dapper的lambda扩展,支持按时间分库分表,也可以自定义分库分表方法.而且可以t4生成实体类免去手写实体类的烦恼.
文档地址: https://liningit.github.io/lnskydb/
开源地址: https://github.com/liningit/lnskydb
nuget地址: https://www.nuget.org/packages/lnskydb/
功能特点
lambda表达式查询方便
基于dapper的lambda表达式扩展可以方便的进行查询筛选操作支持分库分表
默认支持按年分库按月分表,也支持自定义分库分表.从此大数据不用愁t4自动生成实体
有t4模板自动生成实体类,再也不用手写那些烦人的实体类了.仓储类及接口也支持自动生成使用门槛低,快速上手
使用非常简单,可以快速上手
注意问题
本框架只支持单表的lambda表达式查询,如果多表需要手写sql,框架支持根据sql查询修改等.
另外不太建议连表查询,推荐在逻辑层处理
开源协议
上一期我们写了分库分表的增删改查,这一期我们写一下不分库分表的增删改查:
不分库分表
查询
- 根据主键查询
var repository = repositoryfactory.create<productsalebydaynsentity>(); var entity = repository.get(new productsalebydaynsentity { sysno = sysno });
- 根据where条件查询
var sttime = new datetime(2019, 1, 15); var endtime = new datetime(2019, 2, 11); var repository = repositoryfactory.create<productsalebydaynsentity>(); var query = queryfactory.create<productsalebydaynsentity>(m => m.shopname.contains("测试")); query.and(m => m.statisticaldate >= sttime && m.statisticaldate < endtime.date.adddays(1)); query.orderbydescing(m => m.statisticaldate); query.starsize = 20; //可以设置查询行数及开始行数 query.rows = 10; var lst = repository.getlist(query);
- 分页查询
var sttime = new datetime(2019, 1, 15); var endtime = new datetime(2019, 2, 11); var repository = repositoryfactory.create<productsalebydaynsentity>(); var query = queryfactory.create<productsalebydaynsentity>(m => m.shopname.contains("测试")); query.and(m => m.statisticaldate >= sttime); query.and(m => m.statisticaldate < endtime.date.adddays(1)); query.orderbydescing(m => m.statisticaldate); query.starsize = 20; query.rows = 10; var paging = repository.getpaging(query); var count = paging.totalcount; var lst = paging.tolist();//或者paging.items
添加
var addentity = new productsalebydaynsentity() { sysno = guid.newguid(), datasource = "测试来源", productid = guid.newguid(), shopid = guid.newguid(), shopname = "测试店铺", productname = "测试商品", outproductid = guid.newguid().tostring(), importgroupid = guid.newguid(), statisticaldate = datetime.now }; var repository = repositoryfactory.create<productsalebydaynsentity>(); //如果新增主键是自增列会自动赋值自增列值到主键 repository.add(addentity);
更新
- 根据主键更新
var updateentity = new productsalebydaynsentity() { sysno = guid.parse("650bc09c-2b9c-467b-a457-8b4853cc1f0f"), datasource = "测试来源修改", shopname = "店铺修改" }; var repository = repositoryfactory.create<productsalebydaynsentity>(); //根据主键更新其他字段 return repository.update(updateentity);
- 根据where条件更新
var updateentity = new productsalebydaynsentity() { datasource = "测试来源修改", shopname = "店铺修改where", dbmodel_shuffledtempdate = new datetime(2019, 01, 05), }; var repository = repositoryfactory.create<productsalebydaynsentity>(); var where = queryfactory.create<productsalebydaynsentity>(m => m.shopname == "测试店铺1" && m.statisticaldate > new datetime(2019, 01, 03));//where是更新条件 return repository.update(updateentity, where);
删除
- 根据主键删除
var deleteentity = new productsalebydaynsentity() { sysno = guid.parse("650bc09c-2b9c-467b-a457-8b4853cc1f0f") }; var repository = repositoryfactory.create<productsalebydaynsentity>(); return repository.delete(deleteentity);
- 根据where条件删除
var repository = repositoryfactory.create<productsalebydaynsentity>(); var where = queryfactory.create<productsalebydaynsentity>(); //queryisearch方法表示搜索里面空格表示或+表示且 //如 导入+手工 自动+生成 表示字段必须同时拥有导入和手工或者自动和生成 //生成sql是 and ((datasource like '%导入%' and datasource like '%手工%') or datasource like '%自动%' and datasource like '%生成%') where.queryisearch(m => m.datasource, "新+更"); where.queryisearch(m => m.shopname, "批量修改"); //注意如果是更新用的是实体类的dbmodel_shuffledtempdate query中的无效 return repository.delete(where);
上一篇: Java开发工具下载以及环境变量配置
下一篇: 简单背包问题