NDbGate 1.2.8

dotnet add package NDbGate --version 1.2.8
                    
NuGet\Install-Package NDbGate -Version 1.2.8
                    
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="NDbGate" Version="1.2.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NDbGate" Version="1.2.8" />
                    
Directory.Packages.props
<PackageReference Include="NDbGate" />
                    
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 NDbGate --version 1.2.8
                    
#r "nuget: NDbGate, 1.2.8"
                    
#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 NDbGate@1.2.8
                    
#: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=NDbGate&version=1.2.8
                    
Install as a Cake Addin
#tool nuget:?package=NDbGate&version=1.2.8
                    
Install as a Cake Tool

Introduction

NDbGate is a high performance ORM. The framework provides granular level control over persistence/retrieval.

Features

  • .Net Standard 2.1 (tested on .NET 10)
  • Core relationships (One to One, One to Many, Inheritance)
  • Change tracking
  • Data verification on persisting
  • Lazy loading
  • Data migration
  • Strong query language
  • Parallel operation with multiple databases
  • Easily used with legacy databases

Using the library

Run time following dependencies are needed

  • Castle.Core

Quick Start

Define Entities

There are 3 ways to define entities

  • Use attributes
  • Extending an abstract class
  • Registering entities manually

However for ease of understanding here only the annotations based approach would be used.All the entities has to be implemented the interface

IEntity.

The class

DefaultEntity

is designed to used as super class for any entity.

[TableInfo("simple_entity")]
public class SimpleEntity : DefaultEntity
{
	[ColumnInfo(ColumnType.Integer, Key = true)]
	public int Id { get; set; }

	[ColumnInfo(ColumnType.Varchar)]
	public string Name { get; set; }
}

Above class is a entity definition for a class with only 2 columns, first is named id and is a key, latter is a varchar column. Attribute

TableInfo

is used to define the name of the table the class supposed to be mapped.

ColumnInfo

is used to define the table column which the field is supposed to mapped.

Persisting

Persisting is straightforward

SimpleEntity entity = new SimpleEntity();
//set values to the entity
entity.Persist(tx);  //tx is dbgate.ITransaction which created using dbgate.ITransactionFactory 
Retrieving

To retrieve an entity from the database without using dbgate queries, there must be a resultset pointing to the record to fetch.

SimpleEntity entity = new SimpleEntity();
//set values to the entity
entity.Retrieve(rs,tx);  //use the java.sql.ResultSet to the record and tx is dbgate.ITransaction which created using dbgate.ITransactionFactory
Data Migration

Data migration pretty easy

ICollection<Type> entityTypes = new ArrayList<Type>();
entityTypes.Add(typeof(SimpleEntity));
DbGate.GetSharedInstance().PatchDataBase(tx,entityTypes,false); //if the last parameter is true it would drop all the existing tables
Strong queries

Strong queries have support for many complex scenarios like sub queries, unions and group conditions. However for simplicity only a basic example is listed below

ISelectionQuery query = new SelectionQuery()
				.From(QueryFrom.EntityType<SimpleEntity>())
				.Select(QuerySelection.EntityType<SimpleEntity>());
ICollection entities = query.ToList(tx);

More examples can be found in the wiki. Also there is a sample project using the library available in the sources named DbGateTestApp.

Performance

Test entities
public abstract class Item
{
    public int ItemId { get; set; }

    public string Name { get; set; }
}

public class Product : Item
{
    public double UnitPrice { get; set; }

    public double? BulkUnitPrice { get; set; }
}

public class Service : Item
{
    public double HourlyRate { get; set; }
}

public class Transaction
{
    public int TransactionId { get; set; }

    public string Name { get; set; }

    public ICollection<ItemTransaction> ItemTransactions { get; set; }
}

public class ItemTransaction
{
    public int TransactionId { get; set; }

    public int IndexNo { get; set; }

    public Item Item { get; set; }

    public Transaction Transaction { get; set; }

    public ICollection<ItemTransactionCharge> ItemTransactionCharges { get; set; }
}

public class ItemTransactionCharge
{
    public int TransactionId { get; set; }

    public int IndexNo { get; set; }

    public int ChargeIndex { get; set; }

    public string ChargeCode { get; set; }

    public Transaction Transaction { get; set; }

    public ItemTransaction ItemTransaction { get; set; }
}
Test

Inserting/ Querying/ Updating/ Deleting 100, 1000 and 5000 Transaction entities using EF Core (10) and NDbGate against SQL Server LocalDB, measured with BenchmarkDotNet (0.15.8, 1 warmup + 5 iterations). Test project is in the Repo (PerformanceTest).

Environment: .NET 10.0.13, Windows 11, AMD Ryzen AI 9 HX 370.

Results (mean time)
Operation Entities EF Core 10 NDbGate
Insert 100 79.4 ms 132.7 ms
Insert 1000 658.1 ms 1,137.8 ms
Insert 5000 1,903.9 ms 4,871.6 ms
Query 100 188.7 ms 228.8 ms
Query 1000 1,112.9 ms 1,590.4 ms
Query 5000 6,058.2 ms 6,751.3 ms
Update 100 285.0 ms 232.6 ms
Update 1000 1,819.4 ms 1,559.4 ms
Update 5000 8,397.3 ms 8,957.2 ms
Delete 100 279.7 ms 153.1 ms
Delete 1000 1,408.4 ms 2,126.6 ms
Delete 5000 4,764.3 ms 8,766.1 ms
Results (entities per second, 5000 entities)
Operation EF Core 10 NDbGate
Insert 2626 1026
Query 825 741
Update 595 558
Delete 1049 570

License

GNU GPL V3

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 was computed.  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 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

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.2.8 108 10/22/2026
1.2.7 157 5/1/2026
1.2.6 252 4/30/2025
1.2.5 198 2/15/2025
1.2.4 539 12/6/2022
1.2.3 1,759 7/5/2018
1.2.1 1,423 11/27/2017
1.2.0 1,437 11/11/2017
1.1.0 1,464 10/21/2017
1.0.1 1,483 3/6/2016
1.0.0 1,623 10/27/2014