C#: SQL Query Builder Class

后端 未结 5 1059
一整个雨季
一整个雨季 2021-02-14 01:11

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

5条回答
  •  伪装坚强ぢ
    2021-02-14 01:29

    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.

    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));
    

    Note: I am the owner of it

    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: https://sqlkata.com/playground/sqlserver?code=var%20query%20=%20new%20Query(%22Posts%22).Limit(10).Offset(20)%3B

    Oracle: https://sqlkata.com/playground/oracle?code=var%20query%20=%20new%20Query(%22Posts%22).Limit(10).Offset(20)%3B

提交回复
热议问题