C#:SQL查询生成器类 [英] C#: SQL Query Builder Class

查看:60
本文介绍了C#:SQL查询生成器类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到良好的"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::

Difference between different compilers output
MySql: https://sqlkata.com/playground/mysql?code=var%20query%20=%20new%20Query(%22Posts%22).Limit(10).Offset(20)%3B

SqlServer:: Oracle: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆