How to generate model from database using Dapper?

前端 未结 8 1355
故里飘歌
故里飘歌 2020-12-13 00:56

I am coming from PetaPoco camp. PetaPoco has a T4 template which generates model from the database. Is anything similar available for Dapper?

I installed Dapper usi

8条回答
  •  暖寄归人
    2020-12-13 01:52

    I'm the author of a POCO-Generator template called CodegenCS.POCO.

    The link above contains C# and PowerShell Scripts which allow you to build complete POCOs (ready to use in Dapper) which also include override bool Equals(), override int GetHashCode(), and (for those who like it) it includes full ActiveRecord CRUD queries (Insert/Update).

    Check out this example POCO from Northwind database. If you like it, it's very easy to use the templates:

    • Edit the connection string and paths in RefreshSqlServerSchema.csx and invoke it through PowerShell script RefreshSqlServerSchema.ps1 This will Extract the Schema of a SQL Server database into a JSON file
    • Edit the paths and the POCOs Namespace in GenerateSimplePOCOs.csx and invoke it through PowerShell script GenerateSimplePOCOs.ps1 This will Read the JSON Schema and build the POCOs.

    The generator script is very simple to understand and customize.

提交回复
热议问题