mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-05 16:00:52 +08:00
update
@@ -92,39 +92,6 @@ repo.Update(item); //对比快照时的变化
|
||||
//WHERE (`Id` = 1)
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
| 属性 | 返回值 | 说明 |
|
||||
| -- | -- | -- |
|
||||
| EntityType | Type | 仓储正在操作的实体类型,注意它不一定是 TEntity |
|
||||
| UnitOfWork | IUnitOfWork | 正在使用的工作单元 |
|
||||
| Orm | IFreeSql | 正在使用的 Orm |
|
||||
| DbContextOptions | DbContextOptions | 正在使用的 DbContext 设置,修改设置不影响其他 |
|
||||
| DataFilter | IDataFilter\<TEntity\> | 仓储过滤器,本对象内生效 |
|
||||
| Select | ISelect\<TEntity\> | 准备查询数据 |
|
||||
|
||||
| 方法 | 返回值 | 参数 | 说明 |
|
||||
| -- | -- | -- | -- |
|
||||
| AsType | void | Type | 改变仓储正在操作的实体类型 |
|
||||
| Get | TEntity | TKey | 根据主键,查询数据 |
|
||||
| Find | TEntity | TKey | 根据主键,查询数据 |
|
||||
| Delete | int | TKey | 根据主键删除数据 |
|
||||
| Delete | int | Lambda | 根据 lambda 条件删除数据 |
|
||||
| Delete | int | TEntity | 删除数据 |
|
||||
| Delete | int | IEnumerable\<TEntity\> | 批量删除数据 |
|
||||
| Insert | - | TEntity | 插入数据,若实体有自增列,插入后的自增值会填充到实体中 |
|
||||
| Insert | - | IEnumerable\<TEntity\> | 批量插入数据 |
|
||||
| Update | - | TEntity | 更新数据 |
|
||||
| Update | - | IEnumerable\<TEntity\> | 批量更新数据 |
|
||||
| InsertOrUpdate | - | TEntity | 插入或更新数据 |
|
||||
| FlushState | - | 无 | 清除状态管理数据 |
|
||||
| Attach | - | TEntity | 附加实体到状态管理,可用于不查询就更新或删除 |
|
||||
| Attach | - | IEnumerable\<TEntity\> | 批量附加实体到状态管理 |
|
||||
| AttachOnlyPrimary | - | TEntity | 只附加实体的主键数据到状态管理 |
|
||||
| [SaveMany](https://github.com/2881099/FreeSql/wiki/%E8%81%94%E7%BA%A7%E4%BF%9D%E5%AD%98#savemany) | - | TEntity, string | 保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比) |
|
||||
|
||||
> 状态管理,可实现 Update 只更新变化的字段(不更新所有字段),灵活使用 Attach 和 Update 用起来非常舒服。
|
||||
|
||||
## 过滤与验证
|
||||
|
||||
假设我们有User(用户)、Topic(主题)两个实体,在领域类中定义了两个仓储:
|
||||
@@ -295,6 +262,39 @@ int Delete(Expression<Func<TEntity, bool>> predicate);
|
||||
|
||||
DbContext.SaveChanges,或者 Repository 对实体的 Insert/Update/Delete,或者 UnitOfWork.Commit 操作都会最多触发一次该事件。
|
||||
|
||||
## API
|
||||
|
||||
| 属性 | 返回值 | 说明 |
|
||||
| -- | -- | -- |
|
||||
| EntityType | Type | 仓储正在操作的实体类型,注意它不一定是 TEntity |
|
||||
| UnitOfWork | IUnitOfWork | 正在使用的工作单元 |
|
||||
| Orm | IFreeSql | 正在使用的 Orm |
|
||||
| DbContextOptions | DbContextOptions | 正在使用的 DbContext 设置,修改设置不影响其他 |
|
||||
| DataFilter | IDataFilter\<TEntity\> | 仓储过滤器,本对象内生效 |
|
||||
| Select | ISelect\<TEntity\> | 准备查询数据 |
|
||||
|
||||
| 方法 | 返回值 | 参数 | 说明 |
|
||||
| -- | -- | -- | -- |
|
||||
| AsType | void | Type | 改变仓储正在操作的实体类型 |
|
||||
| Get | TEntity | TKey | 根据主键,查询数据 |
|
||||
| Find | TEntity | TKey | 根据主键,查询数据 |
|
||||
| Delete | int | TKey | 根据主键删除数据 |
|
||||
| Delete | int | Lambda | 根据 lambda 条件删除数据 |
|
||||
| Delete | int | TEntity | 删除数据 |
|
||||
| Delete | int | IEnumerable\<TEntity\> | 批量删除数据 |
|
||||
| Insert | - | TEntity | 插入数据,若实体有自增列,插入后的自增值会填充到实体中 |
|
||||
| Insert | - | IEnumerable\<TEntity\> | 批量插入数据 |
|
||||
| Update | - | TEntity | 更新数据 |
|
||||
| Update | - | IEnumerable\<TEntity\> | 批量更新数据 |
|
||||
| InsertOrUpdate | - | TEntity | 插入或更新数据 |
|
||||
| FlushState | - | 无 | 清除状态管理数据 |
|
||||
| Attach | - | TEntity | 附加实体到状态管理,可用于不查询就更新或删除 |
|
||||
| Attach | - | IEnumerable\<TEntity\> | 批量附加实体到状态管理 |
|
||||
| AttachOnlyPrimary | - | TEntity | 只附加实体的主键数据到状态管理 |
|
||||
| [SaveMany](https://github.com/2881099/FreeSql/wiki/%E8%81%94%E7%BA%A7%E4%BF%9D%E5%AD%98#savemany) | - | TEntity, string | 保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比) |
|
||||
|
||||
> 状态管理,可实现 Update 只更新变化的字段(不更新所有字段),灵活使用 Attach 和 Update 用起来非常舒服。
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [《学习FreeSql之一:添加数据》](https://github.com/2881099/FreeSql/wiki/%e6%b7%bb%e5%8a%a0)
|
||||
|
||||
Reference in New Issue
Block a user