ZeroDbs 4.5.0

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

ZeroDbs

Database access library of .net4.5/.net5/.net6/.net8, Support SqlServer/MySql/Sqlite/PostgreSql. Starting from version 4.5, it was completely restructured to support AOT compilation, removing Emit-related reflection usage and encouraging code pre-generation.

Example

using ZeroDbs;

static void Main(string[] args)
{
    //Single database :
    var singelDb = DbFactory.CreateDatabase(
        DbFactory.CreateDbConfig("MySQLite", "SQLite", "data source=./Data/Dbs/testdb.db"), 
        DbFactory.CreateSnowflakeIdGenerator(1, 1));


    //Multiple databases :
    var snowflake = DbFactory.CreateSnowflakeIdGenerator(1, 1);
    var dbs = new System.Collections.Generic.List<IDbConfig>
    {
        DbFactory.CreateDbConfig("Db001","SQLite","data source=./Data/Dbs/testdb.db"),
        DbFactory.CreateDbConfig("Db002","MySql","Server=127.0.0.1;Port=3306;Database=testdb;User Id=root;Password=123456;")
    };
    var dbService = DbFactory.InitializeDbService(snowflake, dbs);
    dbService.AddNewDb(DbFactory.CreateDbConfig("Db003", "SqlServer", "Server=127.0.0.1,1433;Database=TestDb;User Id=sa;Password=123456;"));
    dbService.AddNewDb(DbFactory.CreateDbConfig("Db004", "PostgreSQL", "Host=127.0.0.1;Port=5432;Database=testdb;Username=postgres;Password=123456;"));


    //GetDb
    var db = dbService.GetDb("db001");//SQLite
    //Trying to create table
    db.ExecuteNonQuery(db.RawSqlOptions(
        db.SqlOptions("CREATE TABLE IF NOT EXISTS @n0(@n1 BIGINT PRIMARY KEY NOT NULL,@n2 VARCHAR(255) NOT NULL,@n3 DATETIME NOT NULL);")
        .SetNames("Table001","ID","Name","CreateTime")));

    Console.WriteLine("----------Insert----------");
    var nRows = new List<MyEntity>
    {
        new MyEntity { ID = db.Snowflake.NextId(), Name = "ABC", CreateTime = DateTime.Now },
        new MyEntity { ID = db.Snowflake.NextId(), Name = "DEF", CreateTime = DateTime.Now },
        new MyEntity { ID = db.Snowflake.NextId(), Name = "GHI", CreateTime = DateTime.Now }
    };
    var n = db.Insert<MyEntity>("Table001", nRows, (m, kvs) =>
    {
        kvs["ID"] = m.ID;
        kvs["Name"] = m.Name;
        kvs["CreateTime"] = m.CreateTime;
    });
    Console.WriteLine("Inserted {0} rows", n);

    var where = db.WhereOptions(
                db.WherePartOptions("@n0>@p0").SetFields("ID").SetParams(5l),
                db.WherePartOptions("@n0>=@p0", true).SetFields("CreateTime").SetParams(DateTime.Now.Date.AddDays(-7))
            );//.And(...)

    Console.WriteLine("----------Select----------");
    var rs = db.Select<MyEntity>(
        db.SelectOptions<MyEntity>("Table001")
        .SetTop(5)
        .SetWhere(where)
        .SetOrderby(db.OrderbyOptions("ID", false))
        .SetConverter((r) =>
        {
            return new MyEntity { ID = r.GetValue<long>("ID"), Name = r.GetValue<string>("Name"), CreateTime = r.GetValue<DateTime>("CreateTime") };
        }));

    foreach (var r in rs)
    {
        Console.WriteLine("{0}\t{1}\t{2}", r.ID, r.Name, r.CreateTime);
    }

    Console.WriteLine("----------SelectEach----------");
    db.SelectEach<MyEntity>(
        db.SelectOptions<MyEntity>("Table001")
        .SetTop(10)
        .SetWhere(where)
        .SetOrderby(db.OrderbyOptions("ID", false))
        .SetConverter((r) =>
        {
            return new MyEntity { ID = r.GetValue<long>("ID"), Name = r.GetValue<string>("Name"), CreateTime = r.GetValue<DateTime>("CreateTime") };
        }), 
        //callback
        (m) => {
            Console.WriteLine("{0}\t{1}\t{2}", m.ID, m.Name, m.CreateTime);
        });

    Console.WriteLine("----------Page----------");
    var pageData = db.Page<MyEntity>(
        db.PageOptions<MyEntity>("Table001")
        .SetWhere(where)
        .SetOrderby(db.OrderbyOptions("ID", false))
        .SetPage(1)
        .SetSize(10)
        .SetUniqueField("ID")
        .SetConverter((r) =>
        {
            return new MyEntity { ID = r.GetValue<long>("ID"), Name = r.GetValue<string>("Name"), CreateTime = r.GetValue<DateTime>("CreateTime") };
        }));
    Console.WriteLine("Total {0} rows", pageData.Total);
    foreach (var r in pageData.Rows)
    {
        Console.WriteLine("{0}\t{1}\t{2}", r.ID, r.Name, r.CreateTime);
    }
}

class MyEntity
{
    public long ID { get; set; }
    public string Name { get; set; }
    public DateTime CreateTime { get; set; }
}

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 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 Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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
4.5.0 97 7/6/2026
4.1.0 480 11/19/2025
4.0.0 283 9/4/2024
3.9.9 283 4/11/2024
3.9.6 991 1/16/2023
3.9.5 992 10/26/2022
3.9.4 1,003 10/25/2022
3.9.3 1,016 9/6/2022
3.9.2 1,048 8/15/2022
3.9.1 1,108 7/18/2022
3.9.0 1,137 5/24/2022
3.8.9 1,043 5/22/2022
3.8.8 1,037 5/18/2022
3.8.7 1,136 5/13/2022
3.8.5 1,093 5/9/2022
3.8.4 1,118 5/6/2022
3.8.3 1,115 5/6/2022
3.8.1 1,278 4/24/2022 3.8.1 is deprecated because it is no longer maintained.
3.8.0 1,368 4/19/2022 3.8.0 is deprecated because it is no longer maintained.
Loading failed

Add support for PostgreSQL databases