Query Generator Tool
Supported Databases:
- MsSql
- PostgreSql
Features
- Finding Automatic Id Column
[TableName("Countries")]
public sealed class Country
{
[IdColumn]
public int CountryId { get; set; }
[ColumnName("Name")]
public string CountryName { get; set; }
public string Continent { get; set; }
public string Currency { get; set; }
[IgnoreColumn]
public string CountryNameAndContinent
=> String.Format("{0} - {1}", CountryName, Continent);
}
Insert Query For MsSql
string query = new MsSqlQueryGenerate<Country>()
.GenerateInsertQuery();
+Output: "insert into dbo.Country (CountryName,Continent) values (@CountryName,@Continent)"
Insert Query For PostgreSql
string query = new NpgQueryGenerate<Country>()
.GenerateInsertQuery();
+Output: "insert into dbo.Country (\"CountryName\",\"Continent\") values (@CountryName,@Continent)"
Using With Dapper
Country country = new() { CountryName = "TURKEY", Continent = "ASIA", Currency = "TRY" };
int row = await conn.ExecuteAsync(
query,
country);
Update Query For MsSql
string query = new MsSqlQueryGenerate<Country>()
.GenerateUpdateQuery();
+Output: "update dbo.Country set CountryName=@CountryName,Continent=@Continent where CountryId=@CountryId"
Update Query For PostgreSql
string query = new NpgQueryGenerate<Country>()
.GenerateUpdateQuery();
+Output: "update dbo.Country set \"CountryName\"=@CountryName,\"Continent\"=@Continent where \"CountryId\"=@CountryId"
Using With Dapper
Country country = new() { CountryId = 1, CountryName = "TURKEY", Continent = "ASIA", Currency = "TRY" };
int row = await conn.ExecuteAsync(
query,
country);
Delete Query For MsSql
string query = new MsSqlQueryGenerate<Country>()
.GenerateDeleteQuery();
+Output: "delete from dbo.Country where CountryId=@CountryId"
Delete Query For PostgreSql
string query = new NpgQueryGenerate<Country>()
.GenerateDeleteQuery();
+Output: "delete from dbo.Country where \"CountryId\"=@CountryId"
Using With Dapper
Country country = new() { CountryId = 1 };
int row = await conn.ExecuteAsync(
query,
country);
Select Query For MsSql
string query = new MsSqlQueryGenerate<Country>()
.GenerateGetAllQuery();
+Output: "select CountryId as CountryId,CountryName as CountryName,Continent as Continent,Currency as Currency from dbo.Country order by CountryId"
Select Query For PostgreSql
string query = new NpgQueryGenerate<Country>()
.GenerateGetAllQuery();
+Output: "select \"CountryId\" as CountryId,\"CountryName\" as CountryName,\"Continent\" as Continent,\"Currency\" as Currency from dbo.BaseModel order by \"CountryId\""
Using With Dapper
var result = await conn.QueryAsync<Country>(query);
Select Where Query For MsSql
string query = new MsSqlQueryGenerate<Country>()
.GenerateGetByIdQuery(1);
+Output: "select CountryId as CountryId,CountryName as CountryName,Continent as Continent,Currency as Currency from dbo.Country where CountryId=1"
Select Where Query For PostgreSql
string query = new NpgQueryGenerate<Country>()
.GenerateGetByIdQuery(1);
+Output: "select \"CountryId\" as CountryId,\"CountryName\" as CountryName,\"Continent\" as Continent,\"Currency\" as Currency from dbo.Country where \"CountryId\"=1"
Using With Dapper
var result = await conn.QuerySingleOrDefaultAsync<Country>(query);