.Net平台下兼容.NET Standard 2.0,一个实现以Lambda表达式转转换标准SQL语句,支持MySQL、SQL Server数据库方言,使用强类型操作数据的轻量级ORM工具,在减少魔法字串同时,通过灵活的Lambda表达式组合,实现业务数据查询的多样性。

演示代码:https://github.com/AzThinker/SqlRepoEx2.0Demo

一、SqlRepoEx升级为2.0,此次升级主要变更为

1、重新组织代码结构,以支持SQL方言;

2、增加对MySQL数据访问支持;

3、增加通过Dapper进行数据访问支持;

只需几步,即可实现SqlRepoEx与

(1)、数据库连接设置

string ConnectionString = "Data Source=(Local);Initial Catalog=Northwind;User ID=test;Password=test";

var connectionProvider = new MsSQLP.ConnectionStringConnectionProvider(ConnectionString);

MsSqlRepoFactory.UseConnectionProvider(connectionProvider);

(2)、注册Dapper解释器

MsSqlRepoFactory.UseStatementExecutor(new DapperStatementExecutor(connectionProvider));

MsSqlRepoFactory.UseDataReaderEntityMapper(new DapperEntityMapper());

(3)、标准SqlRepoEx数据访问

var repository = MsSqlRepoFactory.Create<Customers>();

var result = repository.Query().Select(e => e.CustomerID, e => e.CompanyName, e => e.Address).Top(10);

(4)、支持复杂Lambda语法解析;

SqlRepoEx1.1的where语句只支持单一表达式: Where(c => c.Id == 9),如果使用 Where(c => c.Id == 9 && c.Id == 10 ),则会报错;

SqlRepoEx2.0可以使用:Where(c => c.Id > 0 && c.Id < 30 && c.Remark.Contains("a"))的更自然的语法;

(5)、增加对Union操作支持

SqlRepoEx1.1不支持Union操作;

在SqlRepoEx2.0中可以

 var repository = MsSqlRepoFactory.Create<ToDo>();
var results = repository.Query().Select(e => e.Id, e => e.Task);
var results5 = repository.Query().Select(e => e.Id, e => e.Task)
.Where(c => c.Id > && c.Id < );
var results6 = repository.Query()
.Select(e => e.Id, e => e.Task)
.Where(c => c.Id > && c.Id < );
var results2 = results.Union(new List<UnionSql> {
UnionSql.New( results5,UnionType.Union ),
UnionSql.New( results6,UnionType.Union ) });
foreach (var item in results2)
{
Console.WriteLine($"{item.Id}\t {item.Task} ");
}

(6)、增强Join语法

var repository = MsSqlRepoFactory.Create<ToDo>();

var results1 = repository.Query()

.InnerJoin<TaskRemark>()

// 增加附加条件,如果主选择有此属性,则查询本句中所设置

.On<TaskRemark>((r, l) => r.Task == l.Task, l => l.Remark);

Console.WriteLine(results1.Sql());

二、可通过Nuget获得

(一)、MS SQL SqlServer

1、使用 Autofac 时

Install-Package SqlRepoEx.MsSql.Autofac -Version 2.0.1

2、Asp.Net Core

Install-Package SqlRepoEx.MsSql.ServiceCollection -Version 2.0.1

3、手动实例时

Install-Package SqlRepoEx.MsSql.Static -Version 2.0.1

(二)、MySQL

1、使用 Autofac 时

Install-Package SqlRepoEx.MySql.Autofac -Version 2.0.1

2、Asp.Net Core

Install-Package SqlRepoEx.MySql.ServiceCollection -Version 2.0.1

3、手动实例时

Install-Package SqlRepoEx.MySql.Static -Version 2.0.1

(三)、支持Dapper

Install-Package SqlRepoEx.Adapter.Dapper -Version 1.0.1

(四)、通用SQL

Install-Package SqlRepoEx.Normal -Version 2.0.1

(五)、案例源码

https://github.com/AzThinker/SqlRepoEx2.0Demo

如使用中有任何问题,请告知

1、通过评论;

2、可通过电邮 azthinker@sina.com;

3、有兴趣的请在QQ群中参与讨论、联系作者  QQ群名称:ATK高效开发 ,QQ群号:747049962

最新文章

  1. 9月11日上午HTML有序列表、无序列表、网页的格式和布局
  2. HTML5所有标签汇总
  3. 再战map
  4. WEB服务器6--IIS架构补充篇
  5. WinForm 窗体与窗体相互嵌套
  6. 去掉chrome记住密码后自动填充表单的黄色背景
  7. JDBC的java驱动安装
  8. java并发包分析之———AQS框架
  9. 自己实现的typeOf函数1
  10. 1.Linux电源管理-休眠与唤醒
  11. HDU 1560 DNA sequence (迭代加深搜索)
  12. Flask实例化的参数 及 对app的配置
  13. HTTP Status 405 - HTTP method GET is not supported by this URL
  14. SikuliI:安装过程(Windows)
  15. luogu P2365 任务安排
  16. Invalid configuation file. File &quot;**********&quot; was created by a VMware product with more feature than this version of VMware Workstation and cannot be
  17. 以太坊go-ethereum常见问题汇总
  18. 自己第一次使用ANTLR遇到的问题
  19. D - Binary Lexicographic Sequence URAL - 1081 (贪心)
  20. 用python验证蒙提霍尔问题

热门文章

  1. 《Python编程从入门到实践》_第十章_文件和异常
  2. jQuery autocomplete 应用
  3. UML建模概述
  4. Web开发HTTP中URI和URL的情感纠葛
  5. webpack缓存
  6. 获取css样式,style、getComputedStyle及currentStyle的区别
  7. iDempiere 使用指南 windows下eclipse开发环境配置及打包下载
  8. VC6.0静态编译注意事项
  9. Mantis修改“严重性”字段内容
  10. ORACLE_LPAD_FUNCTION