PrimitiveOrm 1.3.1

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

PrimitiveOrm

Small PostgreSQL helper library for the WinForms exam projects.

It is intentionally not a full ORM. It wraps Npgsql, maps query results into simple C# classes, provides reusable CRUD repositories, and supports explicit transactions for checkout-style flows.

Install in a WinForms project

Add a project reference:

dotnet add C:\Users\uphoros\Downloads\winforms_exam\clothing\ClothingStore\ClothingStore.csproj reference C:\Users\uphoros\Downloads\easyORM\PrimitiveOrm.csproj

Then create one database object:

using PrimitiveOrm;

var db = new EasyDb(new DbOptions
{
    Database = "test_db",
    Username = "postgres",
    Password = "1594"
});

To fill the connected database with the bundled exam test schema and data:

db.SetupTestDB();

SetupTestDB() recreates the public schema before importing the dump.

Model example

using PrimitiveOrm;

[Table("users")]
public sealed class User
{
    [Key]
    [Column("id")]
    public int Id { get; set; }

    [Column("username")]
    public string Username { get; set; } = "";

    [Column("password_hash")]
    public string PasswordHash { get; set; } = "";

    [Column("role")]
    public string Role { get; set; } = "";

    [Column("name")]
    public string Name { get; set; } = "";
}

Use [ManualKey] when the primary key is supplied by your code instead of generated by PostgreSQL:

[Table("books")]
public sealed class Book
{
    [Key]
    [ManualKey]
    [Column("book_article")]
    public string Article { get; set; } = "";

    [Column("book_name")]
    public string Name { get; set; } = "";
}

Query example

var user = db.SingleOrDefault<User>(
    "SELECT id, username, password_hash, role, name FROM users WHERE username = @username",
    new { username });

Repository example

var users = db.Repository<User>();

User? user = users.Find(1);
List<User> admins = users.Where("role = @role", new { role = "admin" }, orderBy: "username");

Joins through database views

Repository<T> builds simple single-table queries. To use repository-style reads with joins, create a PostgreSQL view and map a class to that view.

CREATE VIEW order_view AS
SELECT
    o.id,
    o.total_amount,
    u.username
FROM orders o
JOIN users u ON u.id = o.user_id;
using PrimitiveOrm;

[Table("order_view")]
public sealed class OrderView
{
    [Key]
    [Column("id")]
    public int Id { get; set; }

    [Column("total_amount")]
    public decimal TotalAmount { get; set; }

    [Column("username")]
    public string Username { get; set; } = "";
}

var orderViews = db.Repository<OrderView>();

List<OrderView> rows = orderViews.All();
List<OrderView> filtered = orderViews.Where("username = @username", new { username });

Use repositories over views mainly for All, Find, and Where. Insert, Update, and Delete may fail unless the view is updatable or has INSTEAD OF triggers.

Transaction example for sales

using var tx = db.OpenSession(useTransaction: true);

int sellId = db.Scalar<int>(
    @"INSERT INTO sell_history (receipt, sell_date, user_id, total_amount)
      VALUES (@receipt, @sellDate, @userId, @totalAmount)
      RETURNING id",
    new { receipt, sellDate = DateTime.Now, userId, totalAmount },
    tx);

foreach (var item in cartItems)
{
    db.Execute(
        @"INSERT INTO cart (sell_id, tovar_id, kol, price, size, color)
          VALUES (@sellId, @productId, @quantity, @price, @size, @color)",
        new
        {
            sellId,
            productId = item.ProductId,
            quantity = item.Quantity,
            item.Price,
            item.Size,
            item.Color
        },
        tx);
}

tx.Commit();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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 is compatible.  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 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.

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.3.1 71 6/4/2026
1.3.0 72 6/4/2026
1.2.0 72 6/4/2026
1.1.0 72 6/4/2026
1.0.1 85 6/3/2026
1.0.0 93 5/31/2026