Symbol.Data.SqlServer
4.2.0.17
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
.NET Framework 2.0
This package targets .NET Framework 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Symbol.Data.SqlServer --version 4.2.0.17
NuGet\Install-Package Symbol.Data.SqlServer -Version 4.2.0.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="Symbol.Data.SqlServer" Version="4.2.0.17" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Symbol.Data.SqlServer --version 4.2.0.17
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Symbol.Data.SqlServer, 4.2.0.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 Symbol.Data.SqlServer as a Cake Addin #addin nuget:?package=Symbol.Data.SqlServer&version=4.2.0.17 // Install Symbol.Data.SqlServer as a Cake Tool #tool nuget:?package=Symbol.Data.SqlServer&version=4.2.0.17
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
程序集 使用说明
运行时支持 .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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Symbol.Data (>= 4.2.0.43)
- System.Data.Common (>= 4.3.0)
- System.Data.SqlClient (>= 4.8.5)
-
.NETFramework 2.0
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 3.5
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.0
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.5
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.5.2
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.6
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.6.1
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.7
- Symbol.Data (>= 4.2.0.43)
-
.NETFramework 4.8
- Symbol.Data (>= 4.2.0.43)
-
net5.0
- Symbol.Data (>= 4.2.0.43)
- System.Data.SqlClient (>= 4.8.5)
-
net6.0
- Symbol.Data (>= 4.2.0.43)
- System.Data.SqlClient (>= 4.8.5)
-
net7.0
- Symbol.Data (>= 4.2.0.43)
- System.Data.SqlClient (>= 4.8.5)
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.19 | 135 | 4/5/2024 |
4.2.0.18 | 237 | 4/14/2023 |
4.2.0.17 | 198 | 4/14/2023 |
4.1.0.15 | 470 | 4/13/2022 |
4.1.0.14 | 436 | 3/13/2022 |
4.1.0.12 | 535 | 5/8/2020 |
4.1.0.11 | 549 | 12/18/2019 |
4.1.0.10 | 503 | 12/3/2019 |
4.1.0.7 | 496 | 10/12/2019 |
4.1.0.6 | 465 | 10/11/2019 |
4.1.0.5 | 576 | 7/8/2019 |
4.1.0.4 | 512 | 7/5/2019 |
4.1.0.3 | 549 | 6/25/2019 |
4.1.0.2 | 536 | 6/20/2019 |
4.1.0.1 | 508 | 6/16/2019 |
Please see https://github.com/symbolspace/Symbol.Data/wiki/Home for more information.