NDbGate 1.2.6

dotnet add package NDbGate --version 1.2.6
                    
NuGet\Install-Package NDbGate -Version 1.2.6
                    
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.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NDbGate" Version="1.2.6" />
                    
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.6
                    
#r "nuget: NDbGate, 1.2.6"
                    
#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.6
                    
#: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.6
                    
Install as a Cake Addin
#tool nuget:?package=NDbGate&version=1.2.6
                    
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.0
  • 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/ Quering/ Updating/ Deleting 5000 Transaction entities using EF (6.2) and NDbGate. Test project is in the Repo.

Results (entities per second)
EF (9)
Insertion :	8549			
Querying :  6038			
Update : 4360			
Delete	: 5777			
NDbGate
Insertion :	4055
Querying :	2716
Update : 2219
Delete : 2219

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.6 154 4/30/2025
1.2.5 120 2/15/2025
1.2.4 457 12/6/2022
1.2.3 1,516 7/5/2018
1.2.1 1,227 11/27/2017
1.2.0 1,264 11/11/2017
1.1.0 1,279 10/21/2017
1.0.1 1,315 3/6/2016
1.0.0 1,451 10/27/2014