Aore.Dapper.Contrib
1.0.15
dotnet add package Aore.Dapper.Contrib --version 1.0.15
NuGet\Install-Package Aore.Dapper.Contrib -Version 1.0.15
<PackageReference Include="Aore.Dapper.Contrib" Version="1.0.15" />
<PackageVersion Include="Aore.Dapper.Contrib" Version="1.0.15" />
<PackageReference Include="Aore.Dapper.Contrib" />
paket add Aore.Dapper.Contrib --version 1.0.15
#r "nuget: Aore.Dapper.Contrib, 1.0.15"
#:package Aore.Dapper.Contrib@1.0.15
#addin nuget:?package=Aore.Dapper.Contrib&version=1.0.15
#tool nuget:?package=Aore.Dapper.Contrib&version=1.0.15
Aore.Dapper.Contrib — .NET SDK
📈 一个基于Dapper实现一个简单的 .Net 对象映射器的通用工具库,提供了多种数据访问和实用功能的支持的开发组件,助力大量系统和应用取得成功。我将继续保持更新,并正在深度融合更多场景应用👐
使用 Aore.Dapper.Contrib,您可以方便快速将现有项目或新项目实现操作数据支持。
目前 AAore.Dapper.Contrib 支持 .NET Standard 2.0 等多种框架,同时兼容所有 MVC、Razor、WebApi、Console(命令行)、桌面应用(.exe)和后台服务等环境,和外部框架完全解耦。 适用于需要跨平台兼容性的应用程序开发。
希望有更多的人可以从中受益,理解并传播开源的精神,一同助力中国开源事业!感恩一路上给我们提供帮助的朋友们!
如果你喜欢并希望我们继续优化这个项目,请给我们一个 ★Star :)
✨ 功能特性
- 多数据库支持:提供了对多种数据库(MySQL、Oracle、PostgreSQL、SQLite、SQL Server)的访问支持
- 它不仅简化了数据库操作,还提高了代码的可维护性和可移植性,是开发高效、可靠数据库应用程序的理想选择
- 包含一些辅助方法,用于插入、获取、更新和删除记录
- ...
🚀 Aore.Dapper.Contrib 使用示例 :开启你的改造开发之旅!
.NET CLI:
dotnet add package Aore.Dapper.Contrib
或
Nuget包进行搜索下载
🛠 操作使用
扩展方法完整列表
T Get<T>(id);
T GetByWhere<T>(new {Name = "XXX"});
IEnumerable<T> GetAll<T>();
IEnumerable<T> GetAllById<T>(id);
IEnumerable<T> GetAllByWhere<T>(new {Name = "XXX"});
int Insert<T>(T obj);
int Insert<T>(Enumerable<T> list);
int InsertOra<T>(T obj);
bool Update<T>(T obj);
bool Update<T>(T obj, new {Name = "XXX"});
bool UpdateByWhere<T>(new {Name = "NewValue"}, new {Id = "XXX"});
bool Update<T>(Enumerable<T> list);
bool Delete<T>(T obj);
bool Delete<T>(Enumerable<T> list);
bool DeleteByWhere<T>(new {Name = "XXX"});
bool DeleteAll<T>();
为了使这些扩展程序正常工作,相关实体必须具有一个键属性。如果存在名为"id"的属性(不区分大小写),Dapper将自动使用它作为键属性。
public class Car
{
public int Id { get; set; } // Works by convention
public string Name { get; set; }
}
如果实体不遵循此约定,请使用 [Key] 属性来修饰特定属性。
public class User
{
[Key]
int TheId { get; set; }
string Name { get; set; }
int Age { get; set; }
}
Get 方法
根据ID获取特定实体
var car = connection.Get<Car>(1);
表中的所有实体的列表
var cars = connection.GetAll<Car>();
Insert 方法
插入一个实体
connection.Insert(new Car { Name = "Volvo" });
或一个实体列表
connection.Insert(cars);
Update 方法
更新单个实体
connection.Update(new Car() { Id = 1, Name = "Saab" });
或更新实体列表
connection.Update(cars);
Delete 方法
通过指定的 [Key] 属性删除实体
connection.Delete(new Car() { Id = 1 });
实体列表
connection.Delete(cars);
表中的所有实体
connection.DeleteAll<Car>();
特殊属性
Aore.Dapper.Contrib 使用了一些可选的属性:
[Table("Tablename")]- 使用另一个表名,而不是默认的复数形式的类名[Table ("emps")] public class Employee { public int Id { get; set; } public string Name { get; set; } }[Key]- 此属性代表数据库生成的标识符/键public class Employee { [Key] public int EmployeeId { get; set; } public string Name { get; set; } }[Write(true/false)]- 此属性是(不)可写的[Computed]- 此属性为计算得出,不应包含在更新中[Column]- 数据库列名
限制和注意事项
SQLite
SQLiteConnection 暴露了一个与 Dapper.Contrib 提供的 Update 扩展冲突的 Update 事件。有 2 种方法可以处理这个问题。
从
SqlMapperExtensions显式调用Update方法SqlMapperExtensions.Update(_conn, new Employee { Id = 1, Name = "Mercedes" });通过向
Update传递类型参数使方法签名唯一connection.Update<Car>(new Car() { Id = 1, Name = "Maruti" });
✋ 贡献代码
如果需要使用或修改此项目的源代码,建议先Fork。也欢迎将您修改的通用版本Pull Request过来。
- Fork
- 创建您的特性分支 (
git checkout -b my-new-feature) - 提交您的改动 (
git commit -am 'Added some feature') - 将您的修改记录提交到远程
git仓库 (git push origin my-new-feature) - 然后到 github 网站的该
git远程仓库的my-new-feature分支下发起 Pull Request (请提交到Developer分支,不要直接提交到master分支)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- Dapper (>= 2.1.15)
-
.NETStandard 2.0
- Dapper (>= 2.1.15)
- Microsoft.CSharp (>= 4.7.0)
- System.Reflection.Emit (>= 4.7.0)
-
net5.0
- Dapper (>= 2.1.15)
-
net8.0
- Dapper (>= 2.1.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.