commanet.Db.ORMLite 1.1.2

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

commanet.Db.ORMLite


Extension to commanet.Db.SQL package.

Provides lightweight object-oriented interface with SQL Databases.

Idea is to concentrate data structures definition in one place - c# code.

Mapping to DB tables and all operations with data to be performed on the base of

single place defined c# class.

This aproach is useful not everywhere. There are advantages and disadvantages in it.

Prepare Data Structure


// Class Attribute TableName defines real table name used

// in ORM operations. It is optional, if not defined will used

// class name according names convention described below.  

[TableName("MY_REAL_DATABASE_TABLE_NAME")]

// Another optional Attribute defines script to be runned 

// after table created. Script is semicolon separated 

// SQL-operators where can use {TNAME} MACRO - will be filled

// by real table name. 

[PostTableCreateScript(@"

         CREATE UNIQUE INDEX {TNAME}_01 ON {TNAME}(MyCounter);

         CREATE INDEX {TNAME}_02 ON {TNAME}(MyDate);

    ")]

public class MyTableClass

{

    // Attribute ColumnDef defines text to be used in automatically

    // generated  CREATE TABLE sentense     				

    [ColumnDef("INTEGER")]  

    public long MyCounter { get; set; } = 1;

    [ColumnDef("DATE")]

    public DateTime MyDate { get; set; } = DateTime.Now;

    [ColumnDef("VARCHAR2(2000 CHAR)")]

    public string MyString { get; set; } = "";

}

Names convention used to transaltion table and column names from DB and back to c#:

All DB names supposed to be in "Snake Case", all c# names supposed to be in "Camel Case":

Example:

C# | DB

-------------------|-------

MyColumn | MY_COLUMN

MySecondColumn | MY_SECOND_COLUMN

Schema Generation


var db = new SQLDBConnection(DbType, DbUser, DbPassword, DbConStr);

var generator = new ORMDBSchemaGenerator(db, Logger);



generator.AddTableClass<MyTableClass1>();

generator.AddTableClass<MyTableClass2>();



// Optionally can be defined script to be executed after schema generation done

generator.PostGenerationScript = @"

    CREATE USER SOME_USER IDENTIFIED BY SOME_USER;     

    GRANT CONNECT TO SOME_USER;

    GRANT SELECT ON MyTable TO SOME_USER;

    GRANT UPDATE(MY_STRING) ON MY_TABLE TO SOME_USER;

    ...

";

...

// Blow call will check if tables are exists and create them 

// if missing in DB. In current library version it does not

// check if table structure is changed - cretion will happens

// only if table is completely missing

generator.GenerateSchema(DbUser);

Create ORM Helper


var db = new SQLDBConnection(DbType, DbUser, DbPassword, DbConStr);

ORMLite odb = new ORMLite(db);

Using ORM Helper for data manipulation


var SQL = "SELECT * FROM MY_TABLE";

var data = odb.SelectAll<MyTableClass>(SQL);

foreach(row in data)

{

    Console.WriteLine("Data: {0}",row.MyString);

}   

// Variant to read one row 

var oneRow=odb.SelectOne<MyTableClass>(SQL);

With Parameters:


var SQL = "SELECT * FROM MY_TABLE WHERE my_counter=:C";

var data=odb.SelectAll<MyTableClass>( // Returns list of MyTableClass objects

    SQL,

    false, // Do not generate exception if not all object properties filled from query

    DbParams.New("C",123) // Set query parameter

);



foreach(row in data)

{

    Console.WriteLine("Data: {0}",row.MyString);

}   


Modify data in DB.

All data modifications same as in base SQLDBConnection are wrapped in Transaction call with special version of transaction helper provided as input parameter.


var data = new MyTableClass()

{

    MyCounter=1,

    MyDate=DateTime.Now,

    MyString="Hello ORMLite"

}

odb.Transaction((th)=>{ 

  // INSERT Row Into Table

  th.Insert(

    data,          // Object contains data to update

    "MY_TABLE"     // Table Name to Update

  );

 

  // Update Table Row with using  Key(s) 

  th.Update(

    data,          // Object contains data to update

    "MY_TABLE",    // Table Name to Update

    "MY_COUNTER"   // Table key used for update 

  );



  // UPDATE or INSERT if missing in DB 

  th.UpdateOrInsert(

    data,          // Object contains data to update

    "MY_TABLE",    // Table Name to Update

    true,

    "MY_COUNTER"   // Table key used for update 

  );

});







Product 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.  net9.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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.1.2 894 7/29/2020
1.1.1 794 6/24/2020

Initial Release