NDbGate 1.2.4
dotnet add package NDbGate --version 1.2.4
NuGet\Install-Package NDbGate -Version 1.2.4
<PackageReference Include="NDbGate" Version="1.2.4" />
paket add NDbGate --version 1.2.4
#r "nuget: NDbGate, 1.2.4"
// Install NDbGate as a Cake Addin
#addin nuget:?package=NDbGate&version=1.2.4
// Install NDbGate as a Cake Tool
#tool nuget:?package=NDbGate&version=1.2.4
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 (6.2)
Insertion : 457
Querying : 1300
Update : 778
Delete : 900
NDbGate
Insertion : 2100
Querying : 1200
Update : 1100
Delete : 1100
License
GNU GPL V3
Product | Versions 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Castle.Core (>= 5.1.0)
- log4net (>= 2.0.15)
- Microsoft.CSharp (>= 4.7.0)
- System.Data.SqlClient (>= 4.8.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.