Code Monkey home page Code Monkey logo

.net-query-generator's Introduction

WriteParameter

Query Generator Tool

Supported Databases:

  • MsSql
  • PostgreSql

Features
  • Finding Automatic Id Column

Attributes

[TableName("")]
For Table Name Column
  [TableName("Countries")]
   public sealed class Country
   {
       .
       .
       .
   }
[IdColumn]
For Select Id Column
  [IdColumn]
  public int CountryId { get; set; }
[IgnoreColumn]
For Ignore Column
  [IgnoreColumn]
  public string Currency { get; set; }
[ColumnName("")]
For Different Column Name
  [ColumnName("Name")]
  public string CountryName { get; set; }

Using

Example Table Model
[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

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

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

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

Get All

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

Get By Id

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

.net-query-generator's People

Contributors

emir57 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.