egg.db 12.3.2207.17

There is a newer version of this package available.
See the version list below for details.
dotnet add package egg.db --version 12.3.2207.17                
NuGet\Install-Package egg.db -Version 12.3.2207.17                
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="egg.db" Version="12.3.2207.17" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add egg.db --version 12.3.2207.17                
#r "nuget: egg.db, 12.3.2207.17"                
#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 egg.db as a Cake Addin
#addin nuget:?package=egg.db&version=12.3.2207.17

// Install egg.db as a Cake Tool
#tool nuget:?package=egg.db&version=12.3.2207.17                

egg.db

Egg开发套件数据库支持组件

致力于多数据库操作可移植性的类库

本类库支持IConnectionable接口数据库,使用本套件在这些数据库间切换只需编写一套数据库接口实现即可。

依赖关系

组件版本 框架版本 其他依赖版本
12.2.2206.15+ .Net Standard 2.1 egg 12.4.2206.43
12.1.2205.13+ .Net Standard 2.1 egg 12.3.2205.39

数据库申明

Sql Server:

var db = new egg.db.Databases.MicrosoftSqlServer() {
    Address = "127.0.0.1",
    Port = 1433,
    Name = "mater",
    User = "sa",
    Password = "123456"
};

MySql:

var db = new egg.db.Databases.MySql() {
    Address = "127.0.0.1",
    Port = 3306,
    Name = "mysql",
    User = "root",
    Password = "123456"
};

Sqlite:

var db = new egg.db.Databases.Sqlite() {
    Path="/my/temp.db"
};

使用更接近原始SQL数据库操作语句,降低学习成本

建立数据查询,并判断后获取结果:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 创建一个ORM对象
    using (SqlServerSystemTables orm = new SqlServerSystemTables()) {

        // 定义Select语句并读取一行数据
        var row = dbc.Select(orm.SysObjects, orm.SysColumns)
            .Columns(orm.SysColumns.Name)
            .Where((orm.SysObjects.Id == orm.SysColumns.Id) & (orm.SysObjects.Name == "SyatemObjects") & (orm.SysColumns.Name == "Name") & orm.SysObjects.Type.In("S", "U"))
            .GetRow();

        // 判断是否读取到数据
        if (!row.IsEmpty) {

            // 字段定义方式读取数据
            Console.WriteLine($"Name = {row[orm.SysColumns.Name]}");

            // 字符串定义方式读取数据
            Console.WriteLine($"Name = {row["Name"]}");

            // 动态方式读取数据
            dynamic dyc = row;
            Console.WriteLine($"Name = {dyc.Name}");
        }
    }
}

插入数据:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 创建一个ORM对象
    using (SqlServerSystemTables orm = new SqlServerSystemTables()) {

        // 新建一个行数据对象,定义需要插入的数据
        Row row = new Row();
        orm.SysColumns.Rower(row)
            .SetName("123");

        // 创建一个Insert语句并执行
        dbc.Insert(orm.SysColumns, row).Exec();
    }
}

以Id为主键更新数据:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 创建一个ORM对象
    using (SqlServerSystemTables orm = new SqlServerSystemTables()) {

        // 新建一个行数据对象,定义需要插入的数据
        Row row = new Row();
        orm.SysColumns.Rower(row)
            .SetId(1)
            .SetName("123");

        // 创建一个Update语句并执行
        dbc.Update(orm.SysColumns, row, orm.SysColumns.Id).Exec();
    }
}

自定义条件更新数据:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 创建一个ORM对象
    using (SqlServerSystemTables orm = new SqlServerSystemTables()) {

        // 新建一个行数据对象,定义需要插入的数据
        Row row = new Row();
        orm.SysColumns.Rower(row)
            .SetName("123");

        // 创建一个Update语句并执行
        dbc.Update(orm.SysColumns, row)
            .Where(orm.SysColumns.Name == "456")
            .Exec();
    }
}

删除数据:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 创建一个ORM对象
    using (SqlServerSystemTables orm = new SqlServerSystemTables()) {

        // 创建一个Insert语句并执行
        dbc.Delete(orm.SysColumns)
            .Where(orm.SysColumns.Name == "456")
            .Exec();
    }
}

预映射和快速映射

dpz3支持两种ORM结构映射方式:预映射和快速映射

预映射

使用C#针对数据库进行提前ORM类编写

优点:集成化高,表结构清晰,对IDE智能提示友好,使用直观,支持Rower数据操作,可扩展性强,可维护性强

缺点:代码冗余,需要花多余时间编写表结构,开发周期拉长

预映射删除数据示例:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 创建一个ORM对象
    using (SqlServerSystemTables orm = new SqlServerSystemTables()) {

        // 创建一个Delete语句并执行
        dbc.Delete(orm.SysColumns)
            .Where(orm.SysColumns.Name == "456")
            .Exec();

    }
}

快速映射

使用OrmMapper类动态进行ORM操作对象生成

优点:开发迅捷,上手简单

缺点:功能单一,使用者必须提前了解表结构

快速映射删除数据示例:

// 建立数据库连接
using (egg.db.Connection dbc = new egg.db.Connection(db)) {

    // 快速映射表
    var SysColumns = egg.db.OrmMapper.Table("SysColumns");
    // 创建一个Delete语句并执行
    dbc.Delete(SysColumns)
        .Where(SysColumns["Name"] == "456")
        .Exec();

}
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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • egg (>= 12.5.2207.46)

NuGet packages (5)

Showing the top 5 NuGet packages that depend on egg.db:

Package Downloads
egg.Mvc

Egg开发套件中的Mvc组件,提供一些常用建站中的基类和网站服务端配置

egg.db.Sqlite

Egg开发套件中关于Sqlite数据库支持的可选组件

egg.db.MySql

Egg开发套件中关于MySql数据库支持的可选组件

egg.db.PostgreSql

Egg开发套件中关于PostgreSql数据库支持的可选组件

egg.db.MicrosoftSqlServer

Egg开发套件中关于SqlServer数据库支持的可选组件

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
12.6.2210.50 966 10/5/2022
12.3.2207.24 1,211 7/6/2022
12.3.2207.23 706 7/6/2022
12.3.2207.22 738 7/6/2022
12.3.2207.21 707 7/6/2022
12.3.2207.20 491 7/6/2022
12.3.2207.19 754 7/6/2022
12.3.2207.18 708 7/6/2022
12.3.2207.17 733 7/6/2022
12.3.2207.16 968 7/6/2022
12.2.2206.15 1,759 6/20/2022
12.1.2205.14 2,113 5/31/2022
12.1.2205.13 459 5/31/2022
6.0.2112.12 1,070 12/13/2021
6.0.2112.11 373 12/13/2021
2.1.2106.10 799 6/24/2021
2.1.2106.9 501 6/4/2021
2.1.2106.8 421 6/4/2021
2.0.2101.7 1,758 1/24/2021
1.1.2012.6 1,725 12/27/2020
1.1.2012.5 570 12/27/2020
1.1.2012.4 586 12/27/2020
1.1.2012.3 428 12/27/2020
1.1.2012.2 700 12/6/2020
1.0.2011.1 928 11/30/2020