{"id":13508568,"url":"https://github.com/attilaszasz/Pocos-Generator","last_synced_at":"2025-03-30T11:32:14.758Z","repository":{"id":74440839,"uuid":"139966640","full_name":"attilaszasz/Pocos-Generator","owner":"attilaszasz","description":"dotnet-script to generate POCO classes from your database tables and views.","archived":false,"fork":false,"pushed_at":"2018-07-10T07:56:47.000Z","size":16,"stargazers_count":67,"open_issues_count":0,"forks_count":8,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-01T08:33:32.058Z","etag":null,"topics":["dapper","dotnet-script","petapoco","poco","poco-generator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/attilaszasz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-06T09:52:29.000Z","updated_at":"2024-09-29T07:26:53.000Z","dependencies_parsed_at":"2023-02-26T18:31:46.639Z","dependency_job_id":null,"html_url":"https://github.com/attilaszasz/Pocos-Generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attilaszasz%2FPocos-Generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attilaszasz%2FPocos-Generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attilaszasz%2FPocos-Generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attilaszasz%2FPocos-Generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/attilaszasz","download_url":"https://codeload.github.com/attilaszasz/Pocos-Generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314011,"owners_count":20757450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dapper","dotnet-script","petapoco","poco","poco-generator"],"created_at":"2024-08-01T02:00:54.908Z","updated_at":"2025-03-30T11:32:12.851Z","avatar_url":"https://github.com/attilaszasz.png","language":"C#","funding_links":[],"categories":["C#","C# #","others"],"sub_categories":[],"readme":"\nPocos Generator\n===============\n\nWhen all you want are Pocos\n---------------------------\n\nIf you prefer to work with a micro-orm like [Dapper](https://github.com/StackExchange/Dapper), but hate manually writing POCO classes for your tables, this is the right tool for you.  \nA port of [EZPoco T4 templates](https://github.com/davidsavagejr/ezpoco) to .Net Core 2.0+ using [dotnet-script](https://github.com/filipw/dotnet-script/).  \n\nGenerates POCO classes from your database tables and views. For SQL Server, also generates a class with names of stored procedures, and a class with the name and columns of table-valued parameters.  \n\nGetting Started\n===============\n\nPrerequisites\n-------------\n\nThe only prerequisite is [dotnet-script](https://github.com/filipw/dotnet-script/).  \nFollow the [install instructions](https://github.com/filipw/dotnet-script/#installing) for your platform.\n\nUsage\n-----\n\nPocosGenerator works in an opt-in style, regarding your database tables. By default all tables are ignored, you have to manually enable the ones you want to generate a POCO for.  \n\nIn the PocosGenerator.csx file, edit the following section:\n\n```C#\nif (generator.ReadSchema()){\n\n    // Let's remove ignore for tables and views we need\n    /*\n        generator.Tables[\"tablename\"].Ignore = false;\n    */\n\n    generator.Tables[\"Users\"].Ignore = false;\n\n    /*\n        // Tweak Schema\n        generator.Tables[\"tablename\"].Ignore = true;                        // To ignore a table\n        generator.Tables[\"tablename\"].ClassName = \"newname\";                // To change the class name of a table\n        generator.Tables[\"tablename\"][\"columnname\"].Ignore = true;          // To ignore a column\n        generator.Tables[\"tablename\"][\"columnname\"].PropertyName=\"newname\"; // To change the property name of a column\n        generator.Tables[\"tablename\"][\"columnname\"].PropertyType=\"bool\";    // To change the property type of a column\n    */\n\n    generator.GenerateClass();\n}\n```\n\nYou can execute the script from command line:\n\n```shell\ndotnet script PocosGenerator.csx -- output:MyModels.cs connectionstring:ConnectionStrings:MyDatabase config:..\\Config\\connectionstrings.json\n```\n\nParameters are in form of `param:value`, any order.  \n\n Parameter | Default       | Purpose  \n-----------|:-------------:|----------\n output    | DbModels.cs   | Name of created file.\n config    | appsettings.json | Config file to read the connection string from. Relative to script location.\n connectionstring | ConnectionStrings:DefaultConnection | The connection string to use for the database.\n namespace    | Models  | .Net Namespace of the generated classes.\n pocos    | true | Generate POCOs.\n views    | true | Also include views. If false, only tables are considered.\n schema    | null | Restrict to a specific schema (ex. \"dbo.\").\n classprefix    | null | Add a prefix to the generated class names (ex. \"Accounting*TableName*\").\n classsufix    | null | Add a sufix to the generated class names (ex. \"*TableName*Reporting\").\n spclass    | null | Name of the class holding the stored procedures. Not generated if null.\n tvpclass    | null | Name of the class holding the table valued parameters. Not generated if null.\n dapper  | false | Decorate POCOs with attributes for [Dapper.Contrib](https://github.com/StackExchange/Dapper/tree/master/Dapper.Contrib). [Nuget package](https://www.nuget.org/packages/Dapper.Contrib/) must be included in your project.\n\nYou can also run it from [Visual Studio Code](https://code.visualstudio.com/). Install the [C# for Visual Studio Code](https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md) plugin.  \nTo create the launch.json file for you environment, first run this command in the folder containing the .csx files:\n\n```shell\ndotnet script init\n```\n\nWhen running from VS Code, set your options in the PocosGenerator.csx file, this section:\n\n```C#\nif (!Args.Any()){\n    options.Output = \"DbModels.cs\";\n    options.ConfigFilePath = @\"..\\Config\\connectionstrings.json\";\n    options.Namespace = \"Db.Models\";\n    options.ConnectionStringName = \"ConnectionStrings:MyDatabase\";\n    options.SpClass = \"spData\";\n    options.TvpClass = \"tvpData\";\n}\n```\n\nExample usage of the generated classes with Dapper\n--------------------------------------------------\n\n```C#\n        // _connection is an SqlConnection\n        public async Task\u003cIEnumerable\u003cRole\u003e\u003e GetAllRoles()\n        {\n            return await _connection.QueryAsync\u003cRole\u003e(\n                spData.dbo_UsersRole_GetAll,\n                commandType: CommandType.StoredProcedure\n                );\n        }\n```\n\n---\nThis script was tested with SQL Server only. To make it work with other databases, edit the `PocosGenerator.GetDbConnection()` method and return a correct DbConnection instance.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattilaszasz%2FPocos-Generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fattilaszasz%2FPocos-Generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattilaszasz%2FPocos-Generator/lists"}