PocoClassGenerator起於個人工作上需求需要為不同的RDBMS的Table跟View生成Dapper POCO類代碼
,以Necroskillz
的文章 Generate C# POCOs from SQL statement in LINQPad為基礎開端開發功能。
自己身為Dapper、Dapper.Contrib、輕量化愛好者很喜歡這小工具,希望也幫到有需要的版友 :)
全部表格、View批量生成POCO類別代碼
多資料庫
SQLServer、Oracle、MySQL、PostgreSQLOnline Demo : POCO Class Generator GenerateAllTables | .NET Fiddle
The Online Demo : POCO Dapper Contrib Class Generator GenerateAllTables | .NET Fiddle
PM> install-package PocoClassGenerator
GenerateAllTables
方法並顯示生成字串using (var connection = Connection)
{
Console.WriteLine(connection.GenerateAllTables());
}
GeneratorBehavior.DapperContrib
參數using (var conn = GetConnection())
{
var result = conn.GenerateAllTables(GeneratorBehavior.DapperContrib);
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.Comment);
Console.WriteLine(result);
}
using (var connection = Connection)
{
var classCode = connection.GenerateClass("select * from Table");
Console.WriteLine(classCode);
}
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);
}