Skip to content

TheMofaDe/DotNetHelper.ObjectToSql

Repository files navigation

DotNetHelper.ObjectToSql

DotNetHelper.ObjectToSql takes your generic types or dynamic & anonymous objects and convert it to sql.

|| DocumentationAPITutorials || Change Log • || View on Github||

AppVeyor AzureDevOps
Build status Build Status
Package Tests Code Coverage
Build Status Build Status codecov

Features

  • Generating the following sqls from objects & datatables
    • INSERT
    • UPDATE
    • DELETE
    • UPSERT
  • Supports SQLServer OUTPUT CLAUSE Using Expressions
  • Create DBParameters from any type of objects

Supported Databases

  • SQLSERVER
  • SQLITE
  • MYSQL
  • More to come

How to Generate SQL

How to Use With Generics Types
public class Employee {
      public FirstName { get; set; }
      public LastName  { get; set; }
}
 var insertSql = new ObjectToSql(DataBaseType.SqlServer).BuildQuery<Employee>(ActionType.Insert);
 // OR USING EMPLOYEE OBJECT
 var insertSql = new ObjectToSql(DataBaseType.SqlServer).BuildQuery(ActionType.Insert,new Employee());
How to Use With Dynamic Objects
dynamic record = new ExpandoObject();
         record.FirstName = "John";
         record.LastName = "Doe";
var insertSql = new ObjectToSql(DataBaseType.SqlServer).BuildQuery(ActionType.Insert, record, "Employee");
How to Use With Anonymous Objects
var obj = new {FirstName = "John", LastName = "Doe"};
var insertSql = new ObjectToSql(DataBaseType.SqlServer).BuildQuery(ActionType.Insert, obj, "Employee");
How to Generate SQL From DataTables
var insertSql = new DataTableToSql(DataBaseType.SqlServer).BuildQuery(dataTable, ActionType.Insert);

Output

INSERT INTO Employee ([FirstName],[LastName]) VALUES (@FirstName,@LastName)


How to Generate DBParameters

var obj2Sql = new ObjectToSql(DataBaseType.SqlServer); 
var dbParameters = obj2Sql.BuildDbParameterList(new Employee(), (s, o) => new SqlParameter(s, o));


Unit Tests

Unit Test are performed against live instance of databases running via docker containers Make sure you spin up the container via database.ps1

Documentation

For more information, please refer to the Officials Docs

Solution Template

badge

About

DotNetHelper.ObjectToSql takes your generic types or dynamic & anonymous objects and convert it to sql. It also works with DataTable

Resources

License

Stars

Watchers

Forks

Packages

No packages published