标签:write 灵活 HERE service osi amp password 增加 lse
.Net平台下兼容.NET Standard 2.0,一个实现以Lambda表达式转转换标准SQL语句,支持MySQL、SQL Server数据库方言,使用强类型操作数据的轻量级ORM工具,在减少魔法字串同时,通过灵活的Lambda表达式组合,实现业务数据查询的多样性。
1、重新组织代码结构,以支持SQL方言;
2、增加对MySQL数据访问支持;
3、增加通过Dapper进行数据访问支持;
只需几步,即可实现SqlRepoEx与
string ConnectionString = "Data Source=(Local);Initial Catalog=Northwind;User ID=test;Password=test";
var connectionProvider = new MsSQLP.ConnectionStringConnectionProvider(ConnectionString);
MsSqlRepoFactory.UseConnectionProvider(connectionProvider);
MsSqlRepoFactory.UseStatementExecutor(new DapperStatementExecutor(connectionProvider));
MsSqlRepoFactory.UseDataReaderEntityMapper(new DapperEntityMapper());
var repository = MsSqlRepoFactory.Create<Customers>();
var result = repository.Query().Select(e => e.CustomerID, e => e.CompanyName, e => e.Address).Top(10);
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"))的更自然的语法;
SqlRepoEx1.1不支持Union操作;
在SqlRepoEx2.0中可以
1 var repository = MsSqlRepoFactory.Create<ToDo>(); 2 var results = repository.Query().Select(e => e.Id, e => e.Task); 3 var results5 = repository.Query().Select(e => e.Id, e => e.Task) 4 .Where(c => c.Id > 0 && c.Id < 7); 5 var results6 = repository.Query() 6 .Select(e => e.Id, e => e.Task) 7 .Where(c => c.Id > 10 && c.Id < 15); 8 var results2 = results.Union(new List<UnionSql> { 9 UnionSql.New( results5,UnionType.Union ), 10 UnionSql.New( results6,UnionType.Union ) }); 11 foreach (var item in results2) 12 { 13 Console.WriteLine($"{item.Id}\t {item.Task} "); 14 }
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());
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
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
Install-Package SqlRepoEx.Adapter.Dapper -Version 1.0.1
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
标签:write 灵活 HERE service osi amp password 增加 lse
原文地址:https://www.cnblogs.com/athinker/p/9742522.html