Files
Yi.Framework/Yi.Doc.Md/02.框架功能模块/07.仓储.md
2023-12-15 23:44:35 +08:00

28 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 简介
使用仓储用于操作数据库数据,封装通用增删改查等方式
> `ISqlsugarRepository<TEntity>`仓储内置了Sqlsugar Db具有一定的强耦合但是使用起来会非常的舒服方便
** 原因:**Queryable对象是微软内置的查询对象可以使用linq语法同时也是为了Efcore的查询对象Sqlsugar 的查询对象为SugarQueryable对象两者并不兼容SugarQueryable的功能远远大与Queryable为此Sqlsugar不会限制自己而兼容Queryable对象
## 使用方式
方式1依赖注入`IRepository<TEntity>`接口即可
方式2依赖注入`IRepository<TEntity,Guid>`接口即可
方式3依赖注入`ISqlSugarRepository<TEntity>`接口即可
方式4依赖注入`ISqlSugarRepository<TEntity,Guid>`接口即可
方式5继承`SqlSugarRepository<TEntity,Guid>`基类,自定义仓储,注入自己的仓储接口,例如写一个`StudentRepository`继承`SqlSugarRepository<TEntity,Guid>`,再实现自己的`IStudentRepository`,后续使用`IStudentRepository`依赖注册进行使用即可
> 推荐简单常用`ISqlSugarRepository<TEntity,Guid>`的注入
`ISqlSugarRepository`内置了非常多的通用数据库操作方法,同时也内置了`ISqlsugarClient`Db对象在其中
内置方法非常多
- 查询
- 删除
- 修改
- 添加
- 分页查询
- Db对象