.NET Core example of using Dapper with the custom Xml and Json mappers
An example of using Dapper with the custom Xml and Json mappers. Can be used to serialize and deserialize objects by Dapper.
public class BookDescription : IXmlObjectType
{
public Learn Learn { get; set; }
public string About { get; set; }
public Features Features { get; set; }
}
public class Learn
{
public List
}
public class Features
{
public List
}
- Register these new classes in Startup.cs
```csharp
services.RegisterDapperCustomTypeHandlers(typeof(Book).Assembly);
CREATE TABLE [dbo].[Books](
[Id] bigint IDENTITY(1,1) NOT NULL,
[Title] nvarchar(200) NOT NULL,
[Description] xml NULL
CONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED
(
[Id] ASC
)
)
public async Task SaveBook(Book book)
{
using (var conn = _connectionFactory.Connection())
{
await conn.ExecuteAsync(_@"INSERT INTO Books (Title, Description) VALUES (@Title, @Description)", book);
}
}
git clone https://github.com/kubagdynia/DapperMappers.git
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=BookDB;Integrated Security=True;MultipleActiveResultSets=True;"
}
}
dotnet run --project .\DapperMappers\DapperMappers.Api\
https://localhost:5001/swagger
Every commit or pull request is built and tested on the Continuous Integration system.
To test locally:
git clone https://github.com/kubagdynia/DapperMappers.git
dotnet test ./DapperMappers/
List of technologies, frameworks and libraries used for implementation:
This project is licensed under the MIT License.