Build and Execute Queries Against MySql, SqlServer and Postgres in C#
Announcing SqlKata an Elegant Sql Query Builder for C#
Photo by chuttersnap on UnsplashSqlKata is an elegant Sql Query Builder for C#, it helps you to talk with your database engine with a higher order of freedom, it allows you to write complex queries in an Object Oriented Manner, helpful when you need:Complex Reports using subqueries, join, union, CTE and nested conditionsDatabase Abstraction dealing with multiple database vendors, write your query once, and SqlKata will compile it to the needed DatabaseCurrently it support SqlServer, MySql and Postgres, however other database can still be used like Sqlite, but not tested officially by the teamDynamic Queries building your queries on runtime is a must when you have an interactive dashboard or dynamic reports.Building dynamic SQL querySpeed is a matter Unlike Entity Framework, SqlKata doesn’t know about your entities, and doesn’t keep track of them, so no additional memory consumption, just fetch and send, it uses Dapper for the Query Execution so performance here is unbeatableCheck it out https://github.com/sqlkata/querybuilderInstallation$ dotnet add package SqlKataor if you are using the Nuget Package ManagerPM> Install-Package SqlKataFetching dataThe simplest way to get data is to pass the table name in the Query functionvar books = db.Query("Books").Get();After that you can add more Where filtersvar englishBooks = db.Query("Books").Where("Lang", "en").Get();WhereInvar langs = new [] { "en", "fr" };var ltrBooks = db.Query("Books").WhereIn("Lang", langs).Get();Search By Idvar book = db.Query("Books").Where("Id", 100).First();Recent Booksvar books = db.Query("Books").OrderByDesc("PublishDate").Limit(10).Get();Update examplevar affected = db.Query("Books").Where("Score", ">", 1000).Update(new {  Score = 1001});Delete examplevar affected = db.Query("Books").WhereNull("AuthorId").Delete();Insert examplesdb.Query("Books").Insert(new {  Title = "Intro to C#",  AuthorId = 1,});