问题描述
在哪里可以找到良好的"SQL查询"构建器类.我只需要一个简单的类来构建SQL字符串就可以了.对于C#和MySql,我将需要它.我真的不需要像Linq或NHibernate这样的东西.谢谢
Where can I find a good SQL Query builder class. I just need a simple class to build a SQL string and that is it. I will need it for C# and MySql. I really don't need anything like Linq or NHibernate. Thanks
推荐答案
由于Google将我引导至此页面,我建议 SqlKata ,一个简单但功能强大的SqlQuery Builder,它支持嵌套条件,子查询和联接的位置.
Since Google leads me to this page,I would suggest SqlKata, a simple but powerful SqlQuery Builder, that supports nested where conditions, subqueries and joins.
当前它支持SqlServer,MySql和PostgreSql
Currently it supports SqlServer, MySql and PostgreSql
var query = new Query("Users")
.LeftJoin("Countries", "Users.CountryId", "Countries.Id")
.Where("Status", "blocked")
.OrWhereIn("Id", new [] {10, 11, 12})
.OrWhere("LastLogin", ">", DateTime.UtcNow.AddMonths(-5));
注意:我是它的所有者
不同编译器输出之间的差异
MySql:: https://sqlkata.com/playground/mysql?code=var%20query%20=%20new%20Query(%22Posts%22).Limit(10).偏移量(20)%3B
Difference between different compilers output
MySql: https://sqlkata.com/playground/mysql?code=var%20query%20=%20new%20Query(%22Posts%22).Limit(10).Offset(20)%3B
这篇关于C#:SQL查询生成器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!