Db2Forge 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Db2Forge --version 1.0.0
                    
NuGet\Install-Package Db2Forge -Version 1.0.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="Db2Forge" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Db2Forge" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Db2Forge" />
                    
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 Db2Forge --version 1.0.0
                    
#r "nuget: Db2Forge, 1.0.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 Db2Forge@1.0.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=Db2Forge&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Db2Forge&version=1.0.0
                    
Install as a Cake Tool

Db2Forge

A Doctrine-inspired ORM built for DB2/AS400 and .NET Framework (4.6.2, 4.7.2 et 4.8) et .NET 8+. No magic, no bloat — just clean EntityManager, Repository, and Flush-based transactions over ODBC.

License: MIT .NET Framework .NET Framework .NET Framework .NET


Features

  • EntityManager — central entry point, inspired by Doctrine
  • Repository<T> — typed queries with FindAll, FindBy, FindOneBy
  • Criteria — fluent filter builder
  • Unit of WorkPersist / Remove / Update + Flush in a single transaction
  • CallProcedure — stored procedure support with Input / Output parameters
  • Reflection-based mapping via standard .NET attributes ([Table], [Column], [Key])

Requirements

  • .NET 8+
  • IBM i Access ODBC Driver installed on the host machine
  • DB2/AS400 accessible via ODBC

Quick Start

1. Define your entity

Map your AS400 table using standard .NET Data Annotations:

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

[Table("BIB")]
public class MyClass
{
    [Key]
    [Column("FOCMUT")]
    public required string CodeMutation { get; set; }

    [Column("FOORGF")]
    public required string DistManagementState { get; set; }

    [Column("FOCFOR")]
    public required string StatusExplanationCode { get; set; }

    [Column("FONOM")]
    public required string SapNumber { get; set; }

    [Column("FOETAT")]
    public required string NetworkCode { get; set; }

    [Column("DNAIDT")]
    public required DateTime CreationDate { get; set; }

    [Column("DNAQTX")]
    public required string CreationProfile { get; set; }
}

2. Initialize the EntityManager

var manager = new EntityManager(
    "Driver={IBM i Access ODBC Driver};System=SERVER_ISERIES;Uid=ADMIN;Pwd=ADMIN;DefaultLibraries=MYLIBS;"
);

It is better to specify the connection string in the settings or an environment variable than to pass it directly as a parameter.


Usage

Get a Repository

var repo = manager.GetRepository<MyClass>();

Find all records

var entities = repo.FindAll();
Console.WriteLine(entities.Count);

Find with criteria (fluent)

var criteria = new Criteria().Add("FOCMUT", "D");
var result = repo.FindOneBy(criteria);

Multiple conditions:

var criteria = new Criteria()
    .Add("FOORGF", "01")
    .Add("FOCFOR", "SUCCESS");

var results = repo.FindBy(criteria);

Insert

var d = new MyClass
{
    CodeMutation          = "D",
    DistManagementState   = "01",
    StatusExplanationCode = "SUCCESS",
    SapNumber             = "06546546",
    NetworkCode           = "545",
    CreationDate          = DateTime.Now,
    CreationProfile       = "SEBASTIEN"
};

manager.Persist(d);
manager.Flush();

Update

var criteria = new Criteria().Add("FOORGF", "01");
var entity = repo.FindOneBy(criteria);

if (entity != null)
{
    entity.CreationProfile = "DOUTRE";
    manager.Update(entity); // Or if you want specify other conditions => manager.Update(distributor, criteria);
    manager.Flush();
}

Delete

manager.Remove(entity);
manager.Flush();

Batch operations (Unit of Work)

Operations are queued and executed in a single atomic transaction on Flush():

manager.Persist(entityA);
manager.Persist(entityB);
manager.Remove(entityC);
manager.Flush(); // all or nothing

Stored Procedures

Call AS400 stored procedures with typed Input / Output parameters:

var output = manager.CallProcedure("SPLIBPROC", new List<ProcedureParameter>
{
    new("CODEMUT",typeof(string), "D",                    7),
    new("DATEFF", typeof(string), DateTime.Now.ToString("yyyyMMdd"), 8),
    new("QUALIF", typeof(string), "", 1,  ParameterDirection.Output),
    new("CODE",   typeof(string), "", 1,  ParameterDirection.Output),
    new("LIBEL",  typeof(string), "", 30, ParameterDirection.Output),
    new("PRET",   typeof(string), "", 2,  ParameterDirection.Output),
});

Console.WriteLine(output["LIBEL"]?.ToString());

CallProcedure returns a Dictionary<string, object?> containing all Output and InputOutput parameter values.


Entity Mapping Reference

Attribute Target Role
[Table("TABLENAME")] Class Maps to the AS400 physical file
[Column("COLNAME")] Property Maps to the AS400 column name
[Key] Property Marks the primary key (used in WHERE for Update/Delete)

Project Structure

Db2Forge/
├── EntityManager.cs       # Entry point — Persist, Flush, Update, Remove, CallProcedure
├── Repository.cs          # FindAll, FindBy, FindOneBy
├── Dao.cs                 # Raw ODBC layer — Fetch, ExecuteNonQuery, CallProcedure
├── Criteria.cs            # Fluent filter builder
├── ProcedureParameter.cs  # Input/Output parameter descriptor
└── Helpers/
    ├── Mapper.cs          # DataSet → typed object mapping
    └── Formatter.cs       # SQL value formatting

Sébastien Doutre

License

MIT — see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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 Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 154 5/7/2026
1.0.0 153 5/6/2026