Symbol.Data
4.2.0.42
See the version list below for details.
dotnet add package Symbol.Data --version 4.2.0.42
NuGet\Install-Package Symbol.Data -Version 4.2.0.42
<PackageReference Include="Symbol.Data" Version="4.2.0.42" />
paket add Symbol.Data --version 4.2.0.42
#r "nuget: Symbol.Data, 4.2.0.42"
// Install Symbol.Data as a Cake Addin #addin nuget:?package=Symbol.Data&version=4.2.0.42 // Install Symbol.Data as a Cake Tool #tool nuget:?package=Symbol.Data&version=4.2.0.42
程序集 使用说明
运行时支持 .net framework v2.0/3.5/4.0/4.5/4.6/4.7/4.8、.netcoreapp3.1、.net 5.0/6.0 仓库:GitHub、Gitee
- Symbol.Data.dll
- Symbol.Data.SqlServer.dll
- Symbol.Data.PostgreSQL.dll
- Symbol.Data.MySQL.dll
- Symbol.Data.SQLite.dll
最近更新 版本历史
v4.1.0.7 2019-06-26
- 分离到子仓库;
- 本次没有重大更新,可以选择不更新;
简介
- 轻量级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 | Versions 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. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.DependencyModel (>= 3.0.1)
- Symbol (>= 4.0.1.35)
- System.Data.Common (>= 4.3.0)
- System.Runtime.Loader (>= 4.3.0)
-
.NETFramework 2.0
- Symbol (>= 4.0.1.35)
-
.NETFramework 3.5
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.0
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.5
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.5.2
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.6
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.6.1
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.7
- Symbol (>= 4.0.1.35)
-
.NETFramework 4.8
- Symbol (>= 4.0.1.35)
-
net5.0
- Symbol (>= 4.0.1.35)
-
net6.0
- Symbol (>= 4.0.1.35)
-
net7.0
- Symbol (>= 4.0.1.35)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Symbol.Data:
Package | Downloads |
---|---|
Symbol.Data.PostgreSQL
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information. |
|
Symbol.Data.SqlServer
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information. |
|
Symbol.Data.MySql
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information. |
|
Symbol.Data.SQLite
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information. |
|
Symbol.Data.Kingbase
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
4.2.0.50 | 227 | 9/18/2024 | |
4.2.0.49 | 238 | 4/5/2024 | |
4.2.0.46 | 212 | 5/9/2023 | |
4.2.0.45 | 209 | 5/9/2023 | |
4.2.0.44 | 796 | 4/14/2023 | |
4.2.0.43 | 1,364 | 4/13/2023 | |
4.2.0.42 | 230 | 4/13/2023 | |
4.1.0.40 | 995 | 7/21/2022 | |
4.1.0.39 | 459 | 7/21/2022 | |
4.1.0.38 | 460 | 7/21/2022 | |
4.1.0.37 | 452 | 7/21/2022 | |
4.1.0.36 | 1,914 | 4/13/2022 | |
4.1.0.35 | 1,639 | 3/13/2022 | |
4.1.0.33 | 757 | 1/7/2021 | |
4.1.0.32 | 737 | 8/17/2020 | |
4.1.0.29 | 788 | 7/22/2020 | |
4.1.0.28 | 1,993 | 5/8/2020 | |
4.1.0.26 | 1,775 | 12/3/2019 | |
4.1.0.17 | 987 | 10/11/2019 | |
4.1.0.16 | 977 | 8/1/2019 | |
4.1.0.8 | 1,859 | 7/5/2019 | |
4.1.0.7 | 1,918 | 6/25/2019 | |
4.1.0.6 | 854 | 6/24/2019 | |
4.1.0.3 | 1,874 | 6/20/2019 | |
4.1.0.2 | 970 | 6/16/2019 |
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information.