https://github.com/leisaupei/creeper
.NetStandard2.1轻量级ORM
https://github.com/leisaupei/creeper
access dotnet dotnet-core mysql netstandard21 oracle orm postgresql sqlserver
Last synced: 6 months ago
JSON representation
.NetStandard2.1轻量级ORM
- Host: GitHub
- URL: https://github.com/leisaupei/creeper
- Owner: leisaupei
- License: mit
- Created: 2021-01-12T10:07:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-26T16:51:12.000Z (over 3 years ago)
- Last Synced: 2024-11-03T10:12:24.269Z (8 months ago)
- Topics: access, dotnet, dotnet-core, mysql, netstandard21, oracle, orm, postgresql, sqlserver
- Language: C#
- Homepage:
- Size: 1.9 MB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Creeper介绍
[](https://www.nuget.org/packages/Creeper)
[](https://www.nuget.org/packages/Creeper.Access)
[](https://www.nuget.org/packages/Creeper.MySql)
[](https://www.nuget.org/packages/Creeper.Oracle)
[](https://www.nuget.org/packages/Creeper.PostgreSql)
[](https://www.nuget.org/packages/Creeper.Sqlite)
[](https://www.nuget.org/packages/Creeper.SqlServer)
1. 基于.NetStandard2.1的轻量级ORM框架。
2. 适配多种支持的不同种类数据库开发场景。
3. 自带Entity生成器,一键即可生成数据库模型代码。
4. 支持单条记录的自定义数据库缓存,可自定义缓存策略。
5. 支持一主多从数据库策略,自由切换主从。
6. 所有查询支持异步方法。
7. [使用指南](https://github.com/leisaupei/creeper/wiki)
---# 如何开始?
[安装](https://github.com/leisaupei/creeper/wiki/Install)
# 配置DbContext## Startup
``` C#
public void ConfigureServices(IServiceCollection services)
{
services.AddCreeper(options =>
{
//PostgreSqlContext可由生成器生成或继承CreeperContextBase实现即可
options.AddPostgreSqlContext(context =>
{
context.UseCache();
//数据库主从策略 从库优先,没有会报错/从库优先,没有会使用主库/只使用主库
context.UseStrategy(DataBaseTypeStrategy.MainIfSecondaryEmpty);
//添加主库配置
context.UseConnectionString("MainDbConnectionString");
//添加多个从库配置
context.UseSecondaryConnectionString(new[] { "SecondaryDbConnectionStrings" });
});
//此处可添加多种数据库配置, 使用DbContext的对象名称作区分
//options.AddMySqlContext(t =>
//{
// context.UseCache();
// //数据库主从策略 从库优先,没有会报错/从库优先,没有会使用主库/只使用主库
// context.UseStrategy(DataBaseTypeStrategy.MainIfSecondaryEmpty);
// //添加主库配置
// context.UseConnectionString("MainDbConnectionString");
// //添加多个从库配置
// context.UseSecondaryConnectionString(new[] { "SecondaryDbConnectionStrings" });
//});
});
}
```
> ``context.UseCache()``参阅[数据库缓存](https://github.com/leisaupei/creeper/wiki/DbCache)> ``PostgreSqlContext``参阅[DbContext说明](https://github.com/leisaupei/creeper/wiki/DB-First#creepercontext%E8%AF%B4%E6%98%8E)
## Controller或其他注入类
``` C#
public class SomeController : Controller
{
//如果此处使用多个DbContext, 直接使用DbContext名称或使用以下调用方式也行
//private readonly Creeper.Driver.ICreeperContext _context;
//public SomeController(IEnumerable contexts)
//{
// _context = contexts.FirstOrDefault(c => c is PostgreSqlContext);
//}
private readonly Creeper.Driver.ICreeperContext _context;
public SomeController(Creeper.Driver.ICreeperContext context)
{
_context = context;
}[HttpGet]
public DbModel SomeAction()
{
return _context.Select().Where(a => a.DbField == SomeValue).ToOne();
}
}
```