PrimitiveOrm 1.3.1
dotnet add package PrimitiveOrm --version 1.3.1
NuGet\Install-Package PrimitiveOrm -Version 1.3.1
<PackageReference Include="PrimitiveOrm" Version="1.3.1" />
<PackageVersion Include="PrimitiveOrm" Version="1.3.1" />
<PackageReference Include="PrimitiveOrm" />
paket add PrimitiveOrm --version 1.3.1
#r "nuget: PrimitiveOrm, 1.3.1"
#:package PrimitiveOrm@1.3.1
#addin nuget:?package=PrimitiveOrm&version=1.3.1
#tool nuget:?package=PrimitiveOrm&version=1.3.1
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 | Versions 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. |
-
net10.0
- Npgsql (>= 8.0.3)
-
net6.0
- Npgsql (>= 8.0.3)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Npgsql (>= 8.0.3)
-
net9.0
- Npgsql (>= 8.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.