{"id":24402232,"url":"https://github.com/simcubeltd/dapper-generator","last_synced_at":"2025-12-29T11:37:53.201Z","repository":{"id":216014056,"uuid":"740246740","full_name":"SimCubeLtd/dapper-generator","owner":"SimCubeLtd","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-26T20:56:39.000Z","size":45,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-27T06:21:37.187Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/SimCubeLtd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2024-01-07T23:44:35.000Z","updated_at":"2024-04-27T06:21:37.188Z","dependencies_parsed_at":null,"dependency_job_id":"6ca6332b-f835-4d25-b2bf-d0eb9be54da0","html_url":"https://github.com/SimCubeLtd/dapper-generator","commit_stats":null,"previous_names":["simcubeltd/dapper-generator"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimCubeLtd%2Fdapper-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimCubeLtd%2Fdapper-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimCubeLtd%2Fdapper-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimCubeLtd%2Fdapper-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimCubeLtd","download_url":"https://codeload.github.com/SimCubeLtd/dapper-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243358316,"owners_count":20277997,"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":[],"created_at":"2025-01-20T00:59:26.951Z","updated_at":"2025-12-29T11:37:53.161Z","avatar_url":"https://github.com/SimCubeLtd.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Introduction\n**DapperGen** is a .net global tool for generating [Dapper](https://github.com/DapperLib/Dapper) POCO models from a database schema. It is a command line tool that can be used to generate POCO models from a database schema. It is designed to be used as part of a build process to generate models from a database schema.\nIt also supports generating [FluentValidation](https://fluentvalidation.net/) classes for the generated POCOs.\n\nIt is Very fast - a single query collects all data needed for generation\n\n## Installation\n```bash\ndotnet tool install -g SimCube.DapperGenerator\n```\n\n## Usage\n\n```bash\n  ____                                           ____\n |  _ \\    __ _   _ __    _ __     ___   _ __   / ___|   ___   _ __\n | | | |  / _` | | '_ \\  | '_ \\   / _ \\ | '__| | |  _   / _ \\ | '_ \\\n | |_| | | (_| | | |_) | | |_) | |  __/ | |    | |_| | |  __/ | | | |\n |____/   \\__,_| | .__/  | .__/   \\___| |_|     \\____|  \\___| |_| |_|\n                 |_|     |_|\nUSAGE:\n    dappergen [OPTIONS] \u003cCOMMAND\u003e\n\nEXAMPLES:\n    dappergen generate -c \"Server=localhost;Database=MyDatabase;User Id=sa;Password=Password123!\" -o \"./Models\"\n\nOPTIONS:\n    -h, --help       Prints help information\n    -v, --version    Prints version information\n\nCOMMANDS:\n    generate    Generate Dapper POCO models from a database schema\n```\n\n## Options\n```bash\n    -h, --help                       Prints help information\n    -o, --output \u003cOUTPUT\u003e            Generated file path\n        --prefix \u003cPREFIX\u003e            Class name prefix\n        --suffix \u003cSUFFIX\u003e            Class name suffix\n    -n, --namespace \u003cNAMESPACE\u003e      Set class namespace\n    -c, --connection \u003cCONNECTION\u003e    Set MSSQL connection string\n        --validators                 Generate validator class (FluentValidation)\n        --include-json               Include json property names when generating pocos\n\n```\n\n## Generated POCOs\n```csharp\nusing System;\nusing System.Text.Json.Serialization;\n\nnamespace DapperTest.Commercial.Entities;\n\n/// \u003csummary\u003e\n/// Schema: \u003cb\u003eCommercial\u003c/b\u003e\n/// Table Name: \u003cb\u003eProjectTimeSheet\u003c/b\u003e\n/// \u003c/summary\u003e\npublic class ProjectTimeSheet\n{\n\t[JsonPropertyName(\"projectTimeSheetID\")]\n\tpublic int ProjectTimeSheetID { get; set; }\n\n\t[JsonPropertyName(\"employeeID\")]\n\tpublic int EmployeeID { get; set; }\n\n\t[JsonPropertyName(\"sectionID\")]\n\tpublic int SectionID { get; set; }\n\n\t/// \u003csummary\u003e\n\t/// Relationship:\n\t/// Source Table: \u003cb\u003e[Commercial].[ProjectTimeSheet]\u003c/b\u003e\n\t/// Target Table: \u003cb\u003e[Commercial].[ProjectSections]\u003c/b\u003e\n\t/// Foreign Key Property Name: \u003cb\u003eSectionID\u003c/b\u003e.\n\t/// \u003c/summary\u003e\n\t[JsonPropertyName(\"refSectionID\")]\n\tpublic ProjectSection RefSectionID { get; set; }\n\n\t[JsonPropertyName(\"nominalID\")]\n\tpublic int NominalID { get; set; }\n\n\t/// \u003csummary\u003e\n\t/// Relationship:\n\t/// Source Table: \u003cb\u003e[Commercial].[ProjectTimeSheet]\u003c/b\u003e\n\t/// Target Table: \u003cb\u003e[Accounts].[NominalCodes]\u003c/b\u003e\n\t/// Foreign Key Property Name: \u003cb\u003eNominalID\u003c/b\u003e.\n\t/// \u003c/summary\u003e\n\t[JsonPropertyName(\"refNominalID\")]\n\tpublic NominalCode RefNominalID { get; set; }\n\n\t[JsonPropertyName(\"date\")]\n\tpublic DateTime Date { get; set; }\n\n\t[JsonPropertyName(\"hours\")]\n\tpublic decimal Hours { get; set; }\n\n\t[JsonPropertyName(\"rate\")]\n\tpublic decimal Rate { get; set; }\n\n\t[JsonPropertyName(\"comment\")]\n\tpublic string Comment { get; set; }\n\n\t[JsonPropertyName(\"createdBy\")]\n\tpublic int CreatedBy { get; set; }\n\n\t[JsonPropertyName(\"createdDate\")]\n\tpublic DateTime CreatedDate { get; set; }\n}\n```\n\n## Generated Validator Class\n```csharp\nusing FluentValidation;\nusing DapperTest.Commercial.Entities;\n\nnamespace DapperTest.Commercial.Validators;\n\npublic class ProjectTimeSheetValidator : AbstractValidator\u003cProjectTimeSheet\u003e\n{\n\tpublic ProjectTimeSheetValidator()\n\t{\n\t\tRuleFor(entity =\u003e entity.ProjectTimeSheetID).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.EmployeeID).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.SectionID).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.NominalID).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.Date).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.Hours).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.Rate).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.Comment).MaximumLength(250);\n\n\t\tRuleFor(entity =\u003e entity.CreatedBy).NotEmpty();\n\n\t\tRuleFor(entity =\u003e entity.CreatedDate).NotEmpty();\n\t}\n}\n```\n\n## That's cool but I just want the sql query used to generate the POCOs - sure thing :simple_smile:\n```sql\n    SELECT\n          SchemaName = SCHEMA_NAME(t.schema_id),\n          TableName = t.[name],\n          ColumnName = c.[name],\n          ColumnPosition = c.column_id,\n          IsNullable = c.is_nullable,\n          DataType = ty.[name],\n          MaximumLength = COLUMNPROPERTY(c.object_id, c.[name], 'CharMaxLen'),\n          IsIdentity = c.is_identity,\n          IsComputed = c.is_computed,\n          IsPrimary = ISNULL(pk.is_primary_key, 0),\n          RelationshipXML = fk.Relationship\n      FROM sys.tables t\n      INNER JOIN sys.columns c ON c.object_id = t.object_id\n      LEFT JOIN sys.types ty ON ty.user_type_id = c.user_type_id\n      OUTER APPLY (\n          SELECT i.is_primary_key\n          FROM sys.indexes i\n          INNER JOIN sys.index_columns ic ON ic.object_id = i.object_id\n              AND ic.index_id = i.index_id\n              AND ic.column_id = c.column_id\n          WHERE i.object_id = t.object_id\n              AND i.is_primary_key = 1\n      ) pk\n      OUTER APPLY (\n          SELECT\n              SchemaName = SCHEMA_NAME(t2.schema_id),\n              TableName = t2.[name],\n              Relationships = (\n                  SELECT\n                      ParentColumnName = pc.[name],\n                      ReferenceColumnName = rc.[name]\n                  FROM sys.foreign_key_columns fkca\n                  INNER JOIN sys.columns pc ON fkca.parent_column_id = pc.column_id\n                      AND fkca.parent_object_id = pc.object_id\n                  INNER JOIN sys.columns rc ON fkca.referenced_column_id = rc.column_id\n                      AND fkca.referenced_object_id = rc.object_id\n                  WHERE fkca.constraint_object_id = fkc.constraint_object_id\n                      AND fkca.parent_object_id = fkc.parent_object_id\n                  FOR XML PATH('Relationship'), TYPE\n              )\n          FROM sys.foreign_key_columns fkc\n          INNER JOIN sys.tables t2 ON t2.object_id = fkc.referenced_object_id\n          WHERE fkc.parent_column_id = c.column_id\n              AND fkc.parent_object_id = c.object_id\n              AND fkc.constraint_column_id = 1\n          FOR XML PATH('RelationshipRoot')\n      ) fk (Relationship)\n      ORDER BY SchemaName, TableName, ColumnPosition\n```\n\n## Based on\nDapper Class Generator by [Baranovskis](https://github.com/baranovskis/dapper-class-generator/tree/main)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimcubeltd%2Fdapper-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimcubeltd%2Fdapper-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimcubeltd%2Fdapper-generator/lists"}