Blame view

泰额版/Food Labeling Management Code/Yi.Doc.Md/02.框架功能模块教程/07.仓储.md 1.33 KB
59e51671   “wangming”   1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  ## 简介
  使用仓储用于操作数据库数据,封装通用增删改查等方式
  > `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对象