Izayoi.Data.DbDataMapper 1.2.0

dotnet add package Izayoi.Data.DbDataMapper --version 1.2.0
                    
NuGet\Install-Package Izayoi.Data.DbDataMapper -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Izayoi.Data.DbDataMapper" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Izayoi.Data.DbDataMapper" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Izayoi.Data.DbDataMapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Izayoi.Data.DbDataMapper --version 1.2.0
                    
#r "nuget: Izayoi.Data.DbDataMapper, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Izayoi.Data.DbDataMapper@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Izayoi.Data.DbDataMapper&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Izayoi.Data.DbDataMapper&version=1.2.0
                    
Install as a Cake Tool

Izayoi.Data.DbDataMapper

This is a fast micro O/R mapper (ORM) that stores data retrieved from a DB into any object.

Available Databases

A Database with a package that implements classes that inherit from the DbCommand and DbDataReader classes.

Database NuGet GitHub Project
MySQL MySqlConnector MySqlConnector mysqlconnector.net
PostgreSQL Npgsql Npgsql Npgsql
SQL Server Microsoft.Data.Sqlclient - -
SQLite Microsoft.Data.Sqlite - -

Applies to

Product Versions
.NET 8, 9, 10
.NET Standard 2.1
Unity 2021, 2022, 6000

Wiki

Wiki

Examples

Database

-- SQL Server Example
CREATE TABLE [dbo].[users] (
    [id]         INT           IDENTITY (1, 1) NOT NULL,
    [name]       NVARCHAR (50) NOT NULL,
    [age]        TINYINT       NOT NULL,
    [gender]     TINYINT       NOT NULL,
    [created_at] DATETIME2 (7) NOT NULL,
    [updated_at] DATETIME2 (7) NOT NULL,
    PRIMARY KEY CLUSTERED ([id] ASC)
);

Map class

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

//[Table("users")]
[Table("users", Schema = "dbo")]
public class User
{
    [Key]
    [Column("id")]
    public int Id { get; set; }

    [Column("name")]
    public string Name { get; set; } = string.Empty;

    [Column("age")]
    public byte Age { get; set; }

    [Column("gender")]
    public GenderType Gender { get; set; }

    [Column("created_at")]
    public DateTime CreatedAt { get; set; }

    [Column("updated_at")]
    public DateTime UpdatedAt { get; set; }

    [NotMapped]
    public int IgnoreProperty { get; set; }
}
  • If the [Table] attribute is not defined, the class name is used as the table name.
  • If the [Column] attribute is not defined, the property name is used as the column name.
  • If the [NotMapped] attribute is defined, the property is excluded from the mapping.
  • The [Key] attribute is set to the primary key, but is not used by the DbDataMapper alone. (It is used when combined with the DbCommandAdapter class.)

DbDataMapper

using System.Collections.Generic;
using System.Threading.Tasks;
using Izayoi.Data;
using Microsoft.Data.SqlClient;  // for SQL Server
//using Microsoft.Data.Sqlite;   // for SQLite
//using MySqlConnector;          // for MySQL
//using Npgsql;                  // for PostgreSQL

public class Example()
{
    private readonly dbConnectionString;

    private readonly DbDataMapper dbDataMapper = new();

    public async Task Method(CancellationToken cancellationToken)
    {
        using SqlConnection dbConnection = new(dbConnectionString);

        using SqlCommand dbCommand = dbConnection.CreateCommand();

        dbConnection.Open();

        List<User> users;

        // Select method A
        {
            dbCommand.CommandText = "SELECT * FROM dbo.users";

            using SqlDataReader dbDataReader = await dbCommand.ExecuteReaderAsync(cancellationToken);

            users = await dbDataMapper.ReadToObjectsAsync<User>(dbDataReader, cancellationToken);
        }
        // Select method B
        {
            dbCommand.CommandText = "SELECT * FROM dbo.users";

            users = await dbDataMapper.ExecuteQueryAsync<User>(dbCommand, cancellationToken);
        }
        // Select method C
        {
            users = await dbDataMapper.SelectAllAsync<User>(dbCommand, cancellationToken);
        }

        dbConnection.Close();
    }
}

Remarks

Reuse a DbDataMapper object whenever possible.

For a better experience

This library really shines when used in conjunction with the Izayoi.Data.DbCommandAdapter.


Last updated: 24 November, 2025
Editor: Izayoi Jiichan

Copyright (C) 2024 Izayoi Jiichan. All Rights Reserved.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Izayoi.Data.DbDataMapper:

Package Downloads
Izayoi.Data.DbCommandAdapter

This is a database operation support library that includes a fast micro O/R mapper (ORM).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 252 11/24/2025
1.1.0 237 1/5/2025
1.0.0 267 8/16/2024