JCoder.Db4Net.ORM
2.19.5
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 JCoder.Db4Net.ORM --version 2.19.5
NuGet\Install-Package JCoder.Db4Net.ORM -Version 2.19.5
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="JCoder.Db4Net.ORM" Version="2.19.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JCoder.Db4Net.ORM --version 2.19.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JCoder.Db4Net.ORM, 2.19.5"
#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 JCoder.Db4Net.ORM as a Cake Addin
#addin nuget:?package=JCoder.Db4Net.ORM&version=2.19.5
// Install JCoder.Db4Net.ORM as a Cake Tool
#tool nuget:?package=JCoder.Db4Net.ORM&version=2.19.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JCoder.Db4Net.ORM
属性 | |
---|---|
作者(Authors) | Jackie Law |
版权(Copyright) | Copyright © Jackie Law. All rights reserved. |
协议 | MIT |
联系(QQ) | 1378071853 |
联系(Wechat) | JackieLaw1024 |
联系(Email) | JackieLaw-dev@outlook.com |
[TOC]
架构说明
JCoder.Db4Net.ORM | |
---|---|
语言 | C# |
协议 | MIT |
.Net框架 | .Net Standard2.1; .Net Framework 4.7.2; .Net 5; .Net 6; |
简述 | Database类库,一个基于JCoder.Db4Net的ORM库。 |
引用类库
引用类库 | 版本 |
---|---|
JCoder.Db4Net | >=2.19.1 |
相关类库
相关类库 | 说明 |
---|---|
JCoder.Db4Net | 一款为方便使用数据库的操作类库,JCore.Db4Net的新版本。 |
JCoder.Db4Net.ORM | 一个基于JCoder.Db4Net的ORM库,JCore.Db4Net.ORM的新版本。 |
JCoder.Db4Net.Sqlite | 一个基于JCoder.Db4Net且支持Sqlite的库,JCore.Db4Net.Sqlite的新版本。 |
JCoder.Db4Net.MySql | 一个基于JCoder.Db4Net且支持Mysql的库,JCore.Db4Net.MySql的新版本。 |
JCoder.Db4Net.SqlServer | 一个基于JCoder.Db4Net且支持SqlServer的库,JCore.Db4Net.SqlServer的新版本。 |
JCoder.Mock4Net | 一款简易版的用于模拟数据的功能库。 |
获取方式
- 版本要求:>=2.19.1
- 以版本2.19.1为例
获取方式 | 描述 |
---|---|
Package Manager | Install-Package JCoder.Db4Net.ORM -Version 2.19.1 |
.Net CLI | dotnet add package JCoder.Db4Net.ORM --version 2.19.1 |
PackageReference | <PackageReference Include="JCoder.Db4Net.ORM" Version="2.19.1" /> |
Paket CLI | paket add JCoder.Db4Net.ORM --version 2.19.1 |
Script&Interactive | #r "nuget: JCoder.Db4Net.ORM, 2.19.1" |
Cake | // Install as a Cake Addin<br/>#addin nuget:?package=JCoder.Db4Net.ORM&version=2.19.1<br/><br/>// Install as a Cake Tool<br/>#tool nuget:?package=JCoder.Db4Net.ORM&version=2.19.1 |
使用说明
主要类与接口
名称 | 类型 | 描述 |
---|---|---|
Orm | 类 | 工具类,主要用于数据库在数据对象上的通用处理。 |
使用说明
注意事项 | 描述 |
---|---|
函数名称有Entity | 属性数据处理以DbAttribute优先。 |
函数名称有Object | 属性数据有多种处理方式。<br/>OnlyProperty方式直接忽略DbAttribute。<br/>OnlyDbAttribute方式只处理有DbAttribute的。<br/>DbAttributeFirst方式以DbAttribute优先。 |
扩展使用
ToEntity1st(查询数据,并将首条数据转换为数据实例)
// ToEntity1st(查询数据,并将首条数据转换为数据实例) using JCoder.Db4Net; using JCoder.Db4Net.ORM; IDbOperator _operator = new MsSqlFactoryOperator() { ConnectionString = "Server=127.0.0.1;Database=test;Uid = user; Pwd=testpassword;" }; return this.Operator.ToEntity1st<T>("select top 1 * from table1;");
ToEntities(查询数据,并转换为数据实体列表)
// ToEntities(查询数据,并转换为数据实体列表) using JCoder.Db4Net; using JCoder.Db4Net.ORM; IDbOperator _operator = new MsSqlFactoryOperator() { ConnectionString = "Server=127.0.0.1;Database=test;Uid = user; Pwd=testpassword;" }; return this.Operator.ToEntities<T>("select top 10 * from table1;");
CRUD(增删查改)
using JCoder.Db4Net; using JCoder.Db4Net.ORM; // Test Entity Class [DbTable("t_table_test")] public class TestEntity { [DbPrimaryKey] [DbAutoIncrement] public int Key001 { get; set; } [DbPrimaryKey] [DbField(IsUnique=true)] public string Key002 { get; set; } [DbIndex("idx01")] public string C003 { get; set; } } IDbOperator _operator = new MsSqlFactoryOperator() { ConnectionString = "Server=127.0.0.1;Database=test;Uid = user; Pwd=testpassword;" }; TestEntity x = new TestEntity() { Key001 = 101, Key002 = "Test PK", }; // Insert Data(新增数据) this.Operator.Insert<TestEntity>(x); // Update Data(更新数据) x.C003 = "Update Test"; this.Operator.Update<TestEntity>(x); // Delete Data(删除数据) this.Operator.Delete<TestEntity>(x); // Select Data(查询数据) this.Operator.Select1st<TEntity>(" and Key001=101 and Key002-'Test PK'");
Create\Drop Table From Entity(由实体类创建\删除数据库的数据表)
using JCoder.Db4Net; using JCoder.Db4Net.ORM; // Test Entity Class [DbTable("t_table_test")] public class TestEntity { [DbPrimaryKey] [DbAutoIncrement] public int Key001 { get; set; } [DbPrimaryKey] [DbField(IsUnique =true)] public string Key002 { get; set; } [DbIgnore] public string Key003 { get; set; } [DbIndex] [DbField(AllowNull = false, Default = "", Description = "Test Comment")] public string C001 { get; set; } [DbIndex("idx01")] public string C002 { get; set; } [DbIndex("idx01")] public string C003 { get; set; } [DbIgnore] public int C004 { get; set; } [DbField(AllowNull = false, Default = "0", Description = "Test Comment2")] public int C005 { get; set; } [DbNumberFieldExt(Precision = 11, Scale = 2)] public double C006 { get; set; } [DbField(AllowNull = false, Default = "", Description = "Test Comment2")] public string C007 { get; set; } public string C008 { get; set; } [DbTimeFieldExt(UpdateTimeOnCreate = true, UpdateTimeOnUpdate = true)] public DateTime C009 { get; set; } } IDbOperator _operator = new MsSqlFactoryOperator() { ConnectionString = "Server=127.0.0.1;Database=test;Uid = user; Pwd=testpassword;" }; this.Operator.CreateTable<TestEntity>(); this.Operator.DropTable<TestEntity>();
Orm工具类使用
转换首条数据为实体对象(支持DbDataReader、DataTable)
var _table = new DataTable(); // ToEntity1st JCoder.Db4Net.ORM.Orm.ToEntity1st<T>(_table); // ToObject1st JCoder.Db4Net.ORM.Orm.ToObject1st<T>(_table); JCoder.Db4Net.ORM.Orm.ToObject1st<T>(_table, OrmMappingMode.OnlyProperty); JCoder.Db4Net.ORM.Orm.ToObject1st<T>(_table, OrmMappingMode.OnlyDbAttribute); JCoder.Db4Net.ORM.Orm.ToObject1st<T>(_table, OrmMappingMode.DbAttributeFirst);
将数据转换为实体对象(支持DataRow、IDictionary<string, string>、IDictionary<string, object>))
var _dict = new Dictionary<string, string>(); // ToEntity JCoder.Db4Net.ORM.Orm.ToEntity<T>(_dict); // ToObject JCoder.Db4Net.ORM.Orm.ToObject<T>(_dict); JCoder.Db4Net.ORM.Orm.ToObject<T>(_dict, OrmMappingMode.OnlyProperty); JCoder.Db4Net.ORM.Orm.ToObject<T>(_dict, OrmMappingMode.OnlyDbAttribute); JCoder.Db4Net.ORM.Orm.ToObject<T>(_dict, OrmMappingMode.DbAttributeFirst);
将数据源转换为实体对象列表(支持DbDataReader、DataTable)
var _table = new DataTable(); // ToEntities JCoder.Db4Net.ORM.Orm.ToEntities<T>(_table); // ToObjects JCoder.Db4Net.ORM.Orm.ToObjects<T>(_table); JCoder.Db4Net.ORM.Orm.ToObjects<T>(_table, OrmMappingMode.OnlyProperty); JCoder.Db4Net.ORM.Orm.ToObjects<T>(_table, OrmMappingMode.OnlyDbAttribute); JCoder.Db4Net.ORM.Orm.ToObjects<T>(_table, OrmMappingMode.DbAttributeFirst);
将数据填充到已有的实体对象里(支持DbDataReader、DataRow、IDictionary<string, string>、IDictionary<string, object>)
var _source = new DbDataReader(); var _target = new T(); JCoder.Db4Net.ORM.Orm.FillToObject<T>(_target, OrmMappingMode.OnlyProperty, _source); JCoder.Db4Net.ORM.Orm.FillToObject<T>(_target, OrmMappingMode.OnlyDbAttribute, _source); JCoder.Db4Net.ORM.Orm.FillToObject<T>(_target, OrmMappingMode.DbAttributeFirst, _source);
将实体对象转换为DataTable
// 实体对象转换为DataTable DataTable _table = JCoder.Db4Net.ORM.Orm.EntityToDataTable(new T()); DataTable _table = JCoder.Db4Net.ORM.Orm.ObjectToDataTable(new T()); // 实体对象列表转换为DataTable DataTable _table = JCoder.Db4Net.ORM.Orm.EntitiesToDataTable(new List<T>()); DataTable _table = JCoder.Db4Net.ORM.Orm.ObjectsToDataTable(new List<T>());
将实体对象转换为Dictionary<string,string>
// 实体对象转换为Dictionary<string,string> Dictionary<string, string> _dict = JCoder.Db4Net.ORM.Orm.EntityToDict(new T()); Dictionary<string, string> _dict = JCoder.Db4Net.ORM.Orm.ObjectToDict(new T());
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 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. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
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.
-
.NETFramework 4.7.2
- JCoder.Db4Net (>= 2.19.5)
-
.NETStandard 2.1
- JCoder.Db4Net (>= 2.19.5)
-
net5.0
- JCoder.Db4Net (>= 2.19.5)
-
net6.0
- JCoder.Db4Net (>= 2.19.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 |
---|---|---|
2.26.2308.1417 | 177 | 8/14/2023 |
2.21.2211.2117 | 294 | 11/21/2022 |
2.20.12 | 361 | 11/4/2022 |
2.19.5 | 395 | 10/14/2022 |
2.18.6 | 409 | 10/13/2022 |
2.13.3 | 419 | 6/5/2022 |
2.12.3 | 432 | 5/25/2022 |
2.11.4 | 422 | 5/13/2022 |
Please contact Jackie by QQ 1378071853 or E-mail JackieLaw-dev@outlook.com;