{"id":15003035,"url":"https://github.com/kubagdynia/dappermappers","last_synced_at":"2025-10-30T09:31:21.986Z","repository":{"id":91383494,"uuid":"227982086","full_name":"kubagdynia/DapperMappers","owner":"kubagdynia","description":".NET Core example of using Dapper with the custom Xml and Json mappers","archived":false,"fork":false,"pushed_at":"2024-10-10T17:07:33.000Z","size":152,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T07:21:29.764Z","etag":null,"topics":["custom-mapper","custom-xml","dapper","database","dotnet","dotnet-core","json-mappers","json-parser","mssql-database","rest-api","sqlite-database","swashbuckle","xml-mapping","xml-parser"],"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/kubagdynia.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":"2019-12-14T07:14:30.000Z","updated_at":"2024-10-10T17:07:37.000Z","dependencies_parsed_at":"2024-01-17T11:31:02.763Z","dependency_job_id":"e22421f5-0d74-452b-9a7a-89b82dcd9e00","html_url":"https://github.com/kubagdynia/DapperMappers","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/kubagdynia%2FDapperMappers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapperMappers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapperMappers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapperMappers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubagdynia","download_url":"https://codeload.github.com/kubagdynia/DapperMappers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219856480,"owners_count":16556082,"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":["custom-mapper","custom-xml","dapper","database","dotnet","dotnet-core","json-mappers","json-parser","mssql-database","rest-api","sqlite-database","swashbuckle","xml-mapping","xml-parser"],"created_at":"2024-09-24T18:55:19.512Z","updated_at":"2025-10-30T09:31:16.572Z","avatar_url":"https://github.com/kubagdynia.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DapperMappers\n\n[![CI](https://img.shields.io/github/actions/workflow/status/kubagdynia/DapperMappers/dotnet.yml?branch=master)](https://github.com/kubagdynia/DapperMappers/actions?query=branch%3Amaster)\n\nAn example of using Dapper with the custom Xml and Json mappers. Can be used to serialize and deserialize objects by Dapper.\n\n### Project structure\n![](doc/ProjectStructure.png)\n- DapperMappers.Api - Sample REST API that uses serialization and deserialization to XML (uses the MS SQL Server Express database)\n- DapperMappers.Domain - Sample domain used by the REST API\n- DapperMappers.Domain.Tests - Domain tests using SQLite database\n- DbConnectionExtensions - DBConnection extension\n\n### How to use\n- Create a class that implements IXmlObjectType or IJsonObjectType interface\n```csharp\npublic class Book\n{\n\tpublic long Id { get; set; }\n\tpublic string Title { get; set; }\n\tpublic BookDescription Description { get; set; }\n}\n\npublic class BookDescription : IXmlObjectType\n{\n\tpublic Learn Learn { get; set; }\n\tpublic string About { get; set; }\n\tpublic Features Features { get; set; }\n}\n\npublic class Learn\n{\n\tpublic List\u003cstring\u003e Points { get; set; }\n}\n\npublic class Features\n{\n\tpublic List\u003cstring\u003e Points { get; set; }\n}\n```\n- Register these new classes in Startup.cs\n```csharp\nservices.RegisterDapperCustomTypeHandlers(typeof(Book).Assembly);\n```\n- Create a table in the database that contains a column of the XML type\n```sql\nCREATE TABLE [dbo].[Books](\n\t[Id] bigint IDENTITY(1,1) NOT NULL,\n\t[Title] nvarchar(200) NOT NULL,\n\t[Description] xml NULL\n\tCONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED\n\t(\n\t\t[Id] ASC\n\t)\n)\n```\n- Use Dapper to save object data in the database\n```csharp\npublic async Task SaveBook(Book book)\n{\n\tusing (var conn = _connectionFactory.Connection())\n\t{\n\t\tawait conn.ExecuteAsync(_@\"INSERT INTO Books (Title, Description) VALUES (@Title, @Description)\", book);\n\t}\n}\n```\n\n### How to Run test REST API\n- Download and install [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)\n- Download and install [MS SQL Server Express](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb)\n- Create an empty database called BookDB and run [CreateDapperMappersDbSQLServer.sql](https://github.com/kubagdynia/DapperMappers/blob/master/Sql/CreateDapperMappersDbSQLServer.sql) script\n- Clone or download source code\n```\ngit clone https://github.com/kubagdynia/DapperMappers.git\n```\n- Set a database connection string in the API project in the [appsettings.json](https://github.com/kubagdynia/DapperMappers/blob/master/DapperMappers/DapperMappers.Api/appsettings.json)\n```json\n{\n  \"ConnectionStrings\": {\n    \"DefaultConnection\": \"Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BookDB;Integrated Security=True;MultipleActiveResultSets=True;\"\n  }  \n}\n```\n- If you are running from IDE set the Startup Item to the DapperMappers.API project, not IIS Express\n- Running the API project from the command line\n```\ndotnet run --project .\\DapperMappers\\DapperMappers.Api\\\n```\n- Open the API documentation in your browser\n```\nhttps://localhost:5001/swagger\n```\n![](doc/SwaggerBookAPI.png)\n\n### How to Test\nEvery commit or pull request is built and tested on the Continuous Integration system.\n\nTo test locally:\n- Download and install [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)\n- Clone or download source code\n```\ngit clone https://github.com/kubagdynia/DapperMappers.git\n```\n- Start tests from the command line\n```\ndotnet test ./DapperMappers/\n```\n\n### Technologies\nList of technologies, frameworks and libraries used for implementation:\n- [.NET 8.0](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) (platform)\n- [MS SQL Server Express](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb) (database)\n- [Dapper](https://github.com/StackExchange/Dapper) (micro ORM)\n- [Dapper.CustomTypeHandlers](https://github.com/kubagdynia/Dapper.CustomTypeHandlers) (custom handlers)\n- [Automapper](https://github.com/AutoMapper/AutoMapper) (object mapper)\n- [FluentValidation](https://fluentvalidation.net/) (data validation)\n- [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) (JSON serialization/deserialization)\n- [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) (Swagger automated API documentation)\n- [NUnit](https://nunit.org/) (testing framework)\n- [SQLite](https://www.sqlite.org/) (database for testing purpose)\n- [FluentAssertions](https://github.com/fluentassertions/fluentassertions) (fluent API for asserting the result of unit tests)\n\n### License\nThis project is licensed under the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubagdynia%2Fdappermappers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubagdynia%2Fdappermappers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubagdynia%2Fdappermappers/lists"}