PocoClassGenerator is started with Necroskillz
's POCO Generator Generate C# POCOs from SQL statement in LINQPad
- 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
- POCOGenerator Generate Class By Dynamic SQL | .NET Fiddle
- POCO Class Generator GenerateAllTables | .NET Fiddle
- DataTable POCO Class Generator | .NET Fiddle
👇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());
}
- 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
using (var conn = GetConnection())
{
var result = conn.GenerateAllTables(GeneratorBehavior.Comment);
Console.WriteLine(result);
}
using (var conn = GetConnection())
{
var result = conn.GenerateAllTables(GeneratorBehavior.View);
Console.WriteLine(result);
}
using (var conn = GetConnection())
{
var result = conn.GenerateAllTables(GeneratorBehavior.View | GeneratorBehavior.Comment | GeneratorBehavior.DapperContrib);
Console.WriteLine(result);
}
- Generate one class
using (var connection = Connection)
{
var classCode = connection.GenerateClass("select * from Table");
Console.WriteLine(classCode);
}
- 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);
}
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);