Skip to content

Mini POCO Class Generator (Support POCO, DTO, Dapper Contrib)

License

Notifications You must be signed in to change notification settings

mini-software/PocoClassGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet


PocoClassGenerator is started with Necroskillz's POCO Generator Generate C# POCOs from SQL statement in LINQPad

Features

  • Support current DataBase all tables and views generate POCO class code
  • Support Dapper.Contrib
  • Support mutiple RDBMS : sqlserver,oracle,mysql,postgresql
  • mini and faster (only in 5 seconds generate 100 tables code)
  • Use appropriate dialect schema table SQL for each database query

DEMO

20190430141947-image.png

GetStart

👇First : Copy&Paste PocoClassGenerator.cs Code to your project or LINQPad.
or Install from NuGet

PM> install-package PocoClassGenerator

👇Second : Use Connection to call GenerateAllTables and then print it.

using (var connection = Connection)
{
	Console.WriteLine(connection.GenerateAllTables());
}

Support Dapper Contrib POCO Class

  • Just call method with GeneratorBehavior.DapperContrib
using (var conn = GetConnection())
{
    var result = conn.GenerateAllTables(GeneratorBehavior.DapperContrib);
    Console.WriteLine(result);
}

The Online Demo : POCO Dapper Contrib Class Generator GenerateAllTables | .NET Fiddle 20190502132948-image.png

Generate Comment

using (var conn = GetConnection())
{
    var result = conn.GenerateAllTables(GeneratorBehavior.Comment);
    Console.WriteLine(result);
}

Generate View

using (var conn = GetConnection())
{
    var result = conn.GenerateAllTables(GeneratorBehavior.View);
    Console.WriteLine(result);
}

Generate View and Comment and Dapper.Contrib

using (var conn = GetConnection())
{
    var result = conn.GenerateAllTables(GeneratorBehavior.View | GeneratorBehavior.Comment | GeneratorBehavior.DapperContrib);
    Console.WriteLine(result);
}

Generate one class by sql

  1. Generate one class
using (var connection = Connection)
{
	var classCode = connection.GenerateClass("select * from Table");
	Console.WriteLine(classCode);
}
  1. Specify class name
using (var connection = Connection)
{
	var classCode = connection.GenerateClass("with EMP as (select 1 ID,'WeiHan' Name,25 Age) select * from EMP", className: "EMP");
	Console.WriteLine(classCode);
}

DataTablePocoClass

Code at DataTablePocoClassGenerator.cs

var dt = new DataTable();
dt.TableName = "TestTable";
dt.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(string) });

var result = dt.GenerateClass();
var expect =
@"public class TestTable
{
public string ID { get; set; }
}";
Assert.Equal(expect, result);