NickX.TinyORM.Core 1.0.1

Additional Details

Complete Rewrite

dotnet add package NickX.TinyORM.Core --version 1.0.1                
NuGet\Install-Package NickX.TinyORM.Core -Version 1.0.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="NickX.TinyORM.Core" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NickX.TinyORM.Core --version 1.0.1                
#r "nuget: NickX.TinyORM.Core, 1.0.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.
// Install NickX.TinyORM.Core as a Cake Addin
#addin nuget:?package=NickX.TinyORM.Core&version=1.0.1

// Install NickX.TinyORM.Core as a Cake Tool
#tool nuget:?package=NickX.TinyORM.Core&version=1.0.1                

NickX.TinyORM

Description

TinyORM is a very simple and basic object relational mapper for MSSQL-Server databases.

  • Creates the database structure for you
  • Provides basic CRUD functionality (Insert, Update, Delete, Exists)
  • Is managed via Attributes in your models

Setup

Dependencies

NuGet Package

NuGet Gallery | NickX.TinyORM.Core 1.0.0

Get Started

Initialize ConnectionFactory

When letting TinyORM auto-create the database structure, the provided user needs correspnding permissions.

// Build SqlConnectionString
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder()
{
	DataSource = "yourServer,1433",
	InitialCatalog = "yourDatabase",
	UserID = "powerUser",
	Password = "verySecurePassword"
};

/*
OR for example:
var connectionString = @"Server=yourServer,1433;Database=yourDatabase;User Id=powerUser;Password=verySecurePassword";
*/

// Create ConnectionFactory, true -> create structure
IConFactory connectionFactory = new SqlConFactory(builder.ConnectionString, true);

// Register your persistence models, more on model setup later on
connectionFactory.MappingConfiguration.RegisterType<Foo>();
connectionFactory.MappingConfiguration.RegisterType<Bar>();

// Get CRUD handler
CrudHandler<Foo> foos = new CrudHandler<Foo>(connectionFactory);

// Do Stuff
foreach (Foo foo in foos.Get())
{
	Console.WriteLine(foo.ToString());
}

Model preparation

[Table("tbl_foos")] // Custom Table name, if not defined the class name is used
public class Foo
{
	[PrimaryKey(DatabaseGenerated.AutoIncrement)] // Is Primary Key & Auto Generate Id (Identity(1,1))
	[Column("id")] // Column Name = "id"
	public int Id { get; set; }
	
	[Column("name", 50)] // Column Name = "name", Column Length = 50
	public string Name { get; set; }
	
	[Column("lastname", 50)] // Column Name = "lastname", Column Lenth = 50
	public string Lastname { get; set; }
	
	// Column Name = Property name "DateOfBirth"
	public DateTime DateOfBirth { get; set; } 
	
	[Column("notes")] // Column Name = "notes", Column Length = default (nvarchar(max))
	public string Notes { get; set; }
	
	[Ignore] // Ignored by ORM
	public string UnnecessaryNotes { get; set; }
}

CRUD operations

Get

// Get CRUD handler for Foo
CrudHandler<Foo> foos = new CrudHandler<Foo>(connectionFactory);

// Get All
IEnumerable<Foo> all = foos.All();

// Get Single by Primary Key
Foo single = foos.Single(19);

// Get Multiple by filter
IEnumerable<Foo> multiple = foos.Multiple(f => f.Firstname == "Foo");

// Get Single by Filter
Foo single = foos.Single(f => f.Id == 19);

Insert

// Init new Foo
Foo foo = new Foo()
{
	Name = "Foo",
	Lastname = "Bar",
	DateCreate = DateTime.Now
};

// Get CRUD handler for Foo
CrudHandler<Foo> foos = new CrudHandler<Foo>(connectionFactory);

// Insert & get generated key
object key = foos.Insert(foo);

Update

// Get CRUD handler for Foo
CrudHandler<Foo> foos = new CrudHandler<Foo>(connectionFactory);

// Get a Foo by Primary Key
Foo foo = foos.Get(19);

// Work with Foo & update properties
foo.Name = "NewFoo";

// Update Foo
foos.Update(foo);

Delete

// Get CRUD handler for Foo
CrudHandler<Foo> foos = new CrudHandler<Foo>(connectionFactory);

// Delete Foo
foos.Delete(19);

Events

Insert, Update & Delete operations all have events attachted to them.

// Get CRUD handler for Foo
CrudHandler<Foo> foos = new CrudHandler<Foo>(connectionFactory);

// After Insert
foos.OnInsert += (sender, inserted) => {
	Console.WriteLine(string.Format(@"Inserted new Foo with Id: {0}", inserted.Id));
};

// After Update
foos.OnUpdate += (sender, inserted, deleted) => {
	Console.WriteLine(string.Format(@"Updated Foo (old name: {0} // new name: {1})", deleted.Name, inserted.Name));
};

// After Delete
foos.OnDelete += (sender, deleted) => {
	Console.WriteLine(string.Format(@"Deleted Foo with Id: {0}", deleted.Id));
};

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
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.0.1 987 11/9/2021 1.0.1 is deprecated.
1.0.0 894 11/9/2021