Symbol.Data.PostgreSQL 4.2.0.22

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

// Install Symbol.Data.PostgreSQL as a Cake Tool
#tool nuget:?package=Symbol.Data.PostgreSQL&version=4.2.0.22

程序集 使用说明

运行时支持 .net framework v2.0/3.5/4.0/4.5/4.6/4.7/4.8、.netcoreapp3.1、.net 5.0/6.0/7.0 仓库:GitHubGitee

  • Symbol.Data.dll Available on NuGet https://www.nuget.org/packages/Symbol.Data/
  • Symbol.Data.SqlServer.dll Available on NuGet https://www.nuget.org/packages/Symbol.Data.SqlServer/
  • Symbol.Data.PostgreSQL.dll Available on NuGet https://www.nuget.org/packages/Symbol.Data.PostgreSQL/
  • Symbol.Data.MySQL.dll Available on NuGet https://www.nuget.org/packages/Symbol.Data.MySQL/
  • Symbol.Data.SQLite.dll Available on NuGet https://www.nuget.org/packages/Symbol.Data.SQLite/

最近更新 版本历史

v4.2.0.43 2023-04-14

  • 支持.net 7.0;
  • 支持group by 、having 命令,以及SQL解析;
  • 支持count/sum/min/max/avg指令的as操作;
  • select builder若干增强;

简介

  • 轻量级ORM,实体与查询无需一致;
  • 支持T-SQL和NoSQL语法混用;
  • 支持数据库架构版本检测;
  • 数据库:MSSQL 2005/2008/2012/2014/2016+,引用 Symbol.Data.SqlServer
  • 数据库:PostgreSQL,引用 Symbol.Data.PostgreSQL,基于Npgsql.dll;
  • 数据库:MySql,引用 Symbol.Data.MySql,基于 MySql.Data.dll;
  • 数据库:SQLite,引用 Symbol.Data.SQLite,基于 System.Data.SQLite.Core.dll,自适应x64/x86,自动识别;

使用Symbol.Data

  • 引用 Symbol.Data;
  • 引用数据库引擎类库,例如 Symbol.Data.SqlServer;
  • 创建DataContext;
//连接参数,可以是json字符串、匿名对象、IDictionary<string, object>
//省去一些记不住的连接参数,只需要设置关键的参数即可
var connectionOptions = new {
    host = "192.168.247.119\\MSSQL2014",    //服务器,端口为默认,所以不用写
    name = "test",                          //数据库名称
    account = "test",                       //登录账号
    password = "test",                      //登录密码
};

//db 类型:Symbol.Data.IDataContext
var db = Symbol.Data.Provider.CreateDataContext("mssql2012", connectionOptions);
//也可以这样构建
//var db = return new Symbol.Data.SqlServer2012Provider().CreateDataContext(connectionOptions);

//除了使用connectionOptions,也支持原始的连接字符串
//var db = return new Symbol.Data.SqlServer2012Provider().CreateDataContext("Data Source=.;.....");
  • 查询数据
/* -------- 非泛型 -------- */
{
    //单条数据
    var item = db.Find("test", new { name = "xxxxxxxxx" });
    Console.WriteLine( JSON.ToNiceJSON( item ) );
    //查询对象,不进行数据读取操作时,不会实际访问数据库
    var q = db.FindAll("test", new { name = "xxxxxxxxx" }, new { id = "desc" });
    Console.WriteLine( JSON.ToNiceJSON( q ) );
    //可以快速输出List<T>
    var list = q.ToList();
    //可以快速取出第一条 db.Find 就是基于它
    var firstItem = q.FirstOrDefault();
    
    //传统SQL用法
    var q2 = db.CreateQuery("select * from [test] where [name]=@p1 order by [id] desc", "xxxxxxxxx");
}
/* ---------- 泛型 -------- */
{
    //泛型基本上与非泛型差不多,不同之处是指定实体类
    var q = db.FindAll<t_sys_User>(new{ age = 25 });
    //与EF 和 Dapper 不同之处的是,实体类可以不作为表名
    var q2 = db.FindAll<UserInfo>("t_sys_User", new { age = 25 });
}

  • 插入数据
//非泛型操作,指定表名
var id = db.Insert("test", new {
    name = "xxxxxxxxx",
    count = 9999,
    data = new { //JSON类型测试,自动序列化
        url = "https://www.baidu.com/",
        guid = System.Guid.NewGuid(),
        datetime = DateTime.Now,
        values = FastWrapper.As(new {//嵌套复杂对象测试
            nickName = "昵尔",
            account = "test"
        })
    }
});
Console.WriteLine($"insert id={id}");

//泛型插入,唯一用处不用写表名,另外类名发生改变,不用担心错误
var id2 = db.Insert<t_sys_User>(new{
     //类型可以为t_sys_User,也可以为匿名类、IDictionary<string, object>
     //...
});

//如果主键为Guid等特殊类型时
//由于重载有冲突,因此末尾的参数必须传
var guid = db.Insert<System.Guid>("guidtable", {
    name = "test"
},new string[0]);
var guid2 = db.Insert<t_sys_User, System.Guid>(new {
    //...
});

//可以使用ExecuteScalar实例传统的SQL操作
var testId = db.ExecuteScalar<int>("insert into [test]([name]) values(@p1)","xxxxx");

  • 更新数据
//非泛型操作,指定表名
var count = db.Update(
    "test",   //表名
     new {    //更新数据
         name = "fsafhakjshfksjhf",
         count = 88
     }, new { //更新目标,相当于 where 条件
         id 
     });
var updated = (count == 1);
Console.WriteLine($"update {updated}");
  • 删除数据
//匹配规则 类似 mongodb 的规则
var count = db.Delete(
    "test",                          //表名
    new {
        name = "xxxxxxxxx",          //name为xxxxxxxxx
        id = "{ '$gt': 200000 }"     //id大于200000,C#语法不支持JSON,但我们支持嵌套JSON语句 :)
    });
Console.WriteLine($"delete count={count}");

//也可以使用db.ExecuteNoQuery 执行传统SQL
var count2 = db.ExecuteNoQuery("delete from [test] where [name]=@p1 and [id]>@p2", "xxxxxxxxx", 200000);
//@p1 @p2 可以用问号代替
var count3 = db.ExecuteNoQuery("delete from [test] where [name]=? and [id]>?", "xxxxxxxxx", 200000);
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 is compatible.  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.1 is compatible. 
.NET Framework net20 is compatible.  net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  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.2.0.22 80 4/5/2024
4.2.0.21 649 4/14/2023
4.2.0.20 639 4/14/2023
4.2.0.19 597 4/13/2023
4.2.0.18 670 4/13/2023
4.1.0.17 889 9/26/2022
4.1.0.16 877 4/13/2022
4.1.0.15 864 3/13/2022
4.1.0.13 1,054 5/8/2020
4.1.0.12 960 12/3/2019
4.1.0.9 1,038 8/1/2019
4.1.0.8 968 7/8/2019
4.1.0.6 988 7/5/2019
4.1.0.5 948 7/5/2019
4.1.0.4 1,001 6/25/2019
4.1.0.3 1,001 6/23/2019
4.1.0.2 979 6/20/2019
4.1.0.1 979 6/16/2019

Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information.