https://github.com/EminemJK/Banana
🍌 The collection of CRUD helpers for Dapper.
https://github.com/EminemJK/Banana
banana dapper dotnet micro-orm orm redis repository unitofwork
Last synced: about 1 year ago
JSON representation
🍌 The collection of CRUD helpers for Dapper.
- Host: GitHub
- URL: https://github.com/EminemJK/Banana
- Owner: EminemJK
- License: mit
- Created: 2018-11-20T07:05:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T09:35:54.000Z (about 2 years ago)
- Last Synced: 2024-04-03T10:37:17.475Z (about 2 years ago)
- Topics: banana, dapper, dotnet, micro-orm, orm, redis, repository, unitofwork
- Language: C#
- Homepage:
- Size: 2.99 MB
- Stars: 62
- Watchers: 6
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> Developer: Lio.Huang
| Package | NuGet Stable | NuGet Pre-release | Downloads |
| ------- | ------------ | ----------------- | --------- |
| [Banana.Uow](https://www.nuget.org/packages/Banana.Uow/) | [](https://www.nuget.org/packages/Banana.Uow/) | [](https://www.nuget.org/packages/Banana.Uow/) | [](https://www.nuget.org/packages/Banana.Uow/) |
| [Banana.Utility](https://www.nuget.org/packages/Banana.Utility/) | [](https://www.nuget.org/packages/Banana.Utility/) | [](https://www.nuget.org/packages/Banana.Utility/) | [](https://www.nuget.org/packages/Banana.Utility/) |
# Banana.Uow
### 项目介绍
👉[English documentation](https://github.com/EminemJK/Banana/wiki)
基于Dapper封装的仓储、工作单元,支持SQL Server, MySQL, Sqlite,Postgresql,Oracle...
### 一、使用说明
#### 1. 注册链接
``` csharp
ConnectionBuilder.ConfigRegist("strConn", Banana.Uow.Models.DBType.SqlServer);
```
#### 2. 模型
引入命名空间:
``` csharp
using Banana.Uow.Models;
```
创建模型:
``` csharp
[Table("T_Student")]
public class Student : IEntity
{
// if Oracle db
//[Key("user_sequence")]
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int Sex { get; set; }
public int ClassId { get; set; }
[Computed]
public DateTime Createtime { get; set; }
[Column("UserNameFiel")]
public string UserName { get; set; }
}
```
特性说明:
* Table:指定实体对应地数据库表名,如果类名和数据库表名不同,需要设置
* Key:指定此列为自动增长主键(oracle设置序列名称即可)
* ExplicitKey:指定此列为非自动增长主键(例如guid,字符串列)
* Computed:计算属性,此列不作为更新
* Write:指定列是否可写
* Column:指定列名
* ExceptUpdate: 指定该列不需要Update操作
#### 3. 仓储使用
#### 3.1 增删改查
``` csharp
var repo = new Repository();
//查询单个
var model = repo.Query(7);
//查询列表
var list = repo.QueryList("Name like @Name", new { Name = "%EminemJK%" });
//分页查询
var page1 = repo.QueryList(1,5);
var page2 = repo.QueryList(2,5);
… …
var page0 = repo.QueryList(1, 10, "ID>@Id", new { Id = 2 }, "id", false);
//删除
boo b = repo.Delete(model);
boo b = repo.Delete(new Category(){ Id =7 });
//更新
bool model = repo.Update(model);
//插入
int id = (int)repo.Insert(new Student() { Name = "EminemJK",… … });
//批量插入
bool b = repo.InsertBatch(sql,List);
//执行语句
int res = repo.Execute(sql,param);
```
#### 3.2 多数据库时
``` csharp
var dbA = "dbStoreA";
var dbB = "dbStoreA";
ConnectionBuilder.ConfigRegist("strConnA", DBType.SqlServer2012, dbA);
ConnectionBuilder.ConfigRegist("strConnB", DBType.SqlServer2012, dbB);
var userInfo_ReadRepo = new Repository(dbA);
var userInfo_WirteRepo = new Repository(dbA);
Your code ……
```
#### 4. 工作单元
``` csharp
using (UnitOfWork uow = new UnitOfWork())
{
var studentRepo = uow.GetRepository();
var model = new Student("EminemJK");
var sid = studentRepo.Insert(model);
var classRepo = uow.GetRepository();
var cid = classRepo.Insert(new MClass("Fifth Grade"));
if (sid > 0 && cid > 0)
{
uow.Commit();
}
else
{
uow.Rollback();
}
}
```
多数据库时
``` csharp
using (UnitOfWork uow = new UnitOfWork(IDbConnection context))
{
Your code
}
```
OR
``` csharp
using (UnitOfWork uow = new UnitOfWork("dbKey"))
{
Your code
}
```
#### 5.日志记录
[MiniProfiler](https://github.com/MiniProfiler/dotnet)
# Banana.Utility
### 公用库 Utility
| Name| Use |
| ------- | ------- |
| RedisUtils | 基于StackExchange.Redis封装 |
| PinYin | 拼音帮助类|
| JavaDate | 时间戳 |
| ModelConvertUtil | 模型拷贝 |
| PagingUtil | 分页 |
| HttpHelper | easy Get & Post |
| EnumDescription | 枚举特性说明 |
| Encryption | 常用加密解密,DES/MD5/RSA |
## To Be Continued
👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍
-------
License
-------
[MIT](https://github.com/EminemJK/Banana/blob/master/LICENSE)