OpenNetORM.Base 1.0.0

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

OpenNetORM

A lightweight ORM for .NET built on top of ADO.NET. No code generation, no heavy abstractions. Just a clean API over plain C# classes and a set of attributes to describe your schema.

Targets .NET 10 and supports SQLite, MySQL, and Oracle out of the box. Adding a new provider is a matter of implementing two interfaces.


Projects

Project Description
OpenNetORM.Base Core abstractions, base Database class, query builder, attributes
OpenNetORM.Sqlite SQLite provider via Microsoft.Data.Sqlite
OpenNetORM.MySql MySQL provider via MySqlConnector
OpenNetORM.Oracle Oracle provider via Oracle.ManagedDataAccess

Getting started

Define an entity by implementing IDatabaseSerializedClass and decorating it with attributes:

[ClassTableName("users")]
public class User : IDatabaseSerializedClass
{
    [PrimaryKey, AutoIncrement, ColumnName("id")]
    public int Id { get; set; }

    [ColumnName("name"), NotNull]
    public string Name { get; set; } = "";

    [ColumnName("email")]
    public string Email { get; set; } = "";

    [ColumnName("age")]
    public int Age { get; set; }

    public void LoadValues(object?[] parameters)
    {
        int i = 0;
        Id    = Convert.ToInt32(parameters[i++]);
        Name  = (string?)parameters[i++] ?? "";
        Email = (string?)parameters[i++] ?? "";
        Age   = Convert.ToInt32(parameters[i++]);
    }

    public void SetDatabaseReference(IDatabase db) { }
}

Open a connection and register the type:

using var db = new SqliteDatabase("my.db");
db.Open();
db.RegisterType<User>();

CRUD

// Insert
db.Insert(new User { Name = "Alice", Email = "alice@example.com", Age = 30 });

// Query by primary key
var user = db.QueryClass<User>(1);

// Update
user.Age = 31;
db.Update(user);

// Save (insert or update depending on PK)
db.Save(user);

// Delete
db.Delete(user);

Query builder

// Basic filter
var adults = db.Query<User>()
    .Where("age >= @0", 18)
    .OrderBy("name")
    .ToList();

// Conditional filter
var results = db.Query<User>()
    .WhereIf(searchTerm is not null, "name LIKE @0", $"%{searchTerm}%")
    .ToList();

// Pagination
var page = db.Query<User>()
    .OrderBy("id")
    .Skip(0).Take(20)
    .ToList();

// Aggregates
int count = db.Query<User>().Where("age > @0", 25).Count();
bool any = db.Query<User>().Where("name = @0", "Bob").Any();

// Debug
string sql = db.Query<User>().Where("age > @0", 18).ToSql();

Every method has an async counterpart (ToListAsync, CountAsync, AnyAsync, etc.).


Raw SQL

SQLResult result = db.Query("SELECT * FROM users WHERE age > @0", db.CreateParameter("@0", 25));
int affected = db.NonQuery("UPDATE users SET active = 1 WHERE id = @0", db.CreateParameter("@0", 1));
int count = db.Scalar<int>("SELECT COUNT(*) FROM users");

// Paginated raw query
SQLResult page = db.QueryPaginated("SELECT * FROM users ORDER BY id", limit: 10, offset: 0);

Transactions

using var tx = db.BeginTransaction();
db.Insert(new User { Name = "Eve", Age = 22 });
db.Insert(new User { Name = "Frank", Age = 27 });
tx.Commit();

Migrations

Migrate() compares the registered entity types against the current schema and applies any pending changes (new tables, new columns). Each run is recorded in __orm_migrations.

db.FindCompatibleTypes(); // scans all loaded assemblies
db.Migrate();

Change tracking

Implement IChangeTrackable on your entity to get optimized UPDATE statements that only touch modified columns:

var user = db.QueryClass<User>(1);
user.Age = 99;

Console.WriteLine(user.IsModified); // true
Console.WriteLine(user.GetOriginalValues()["age"]); // original value

db.Update(user);  // only updates the age column
user.RejectChanges();  // rolls back to original values in memory

Interceptors

public class LoggingInterceptor : IDbInterceptor
{
    public void OnExecuting(string sql, DbParameter[] parameters) =>
        Console.WriteLine($"Executing: {sql}");
}

db.AddInterceptor(new LoggingInterceptor());

DatabaseManager

A simple static registry for named connections:

DatabaseManager.AddDatabase("main", db);

// elsewhere
var db = DatabaseManager.GetDatabase("main");

Attributes reference

Attribute Target Description
[ClassTableName("name")] Class Maps the class to a specific table name
[PrimaryKey] Property Marks the primary key
[AutoIncrement] Property Sets the column as auto-increment
[ColumnName("name")] Property Maps the property to a specific column name
[NotNull] Property Adds a NOT NULL constraint
[Unique] Property Adds a UNIQUE constraint
[Index] Property Creates an index on the column
[ForeignKey(typeof(T))] Property Declares a foreign key relationship
[Cascade(Insert=true, Update=true)] Property Controls cascade behavior
[NotMapped] Property Excludes the property from ORM mapping

Fluent configuration

Attributes can also be replaced or combined with a ModelBuilder for code-first configuration:

var builder = new ModelBuilder();
builder.Entity<User>(e =>
{
    e.ToTable("users");
    e.Property(u => u.Id).IsPrimaryKey().IsAutoIncrement();
    e.Property(u => u.Name).HasColumnName("name").IsRequired();
});

Adding a provider

Implement ISqlDialect and ITypeMapper, then subclass Database:

public class MyDatabase : Database
{
    protected override DbProviderFactory ProviderFactory => MyProviderFactory.Instance;

    public MyDatabase(string connectionString)
        : base(new MyDialect(), new MyTypeMapper(), connectionString) { }
}

License

MIT Licence

Copyright 2026 txrbo_raccoon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on OpenNetORM.Base:

Package Downloads
OpenNetORM.Sqlite

SQLite provider for OpenNetORM.

OpenNetORM.MySql

MySQL provider for OpenNetORM.

OpenNetORM.Oracle

Oracle provider for OpenNetORM (Oracle 12c+).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 112 6/11/2026
0.1.0 133 6/11/2026