我有 2 个期货(db 表上的 2 个操作),我希望在保存修改之前检查两个期货是否已成功完成。
现在,我在第一个(作为依赖)中开始第二个未来,但我知道这不是最好的选择。我知道我可以使用for-comprehension 并行执行两个期货,但即使一个失败,另一个也会被执行(尚未测试)
firstFuture.dropColumn(tableName) match {
case Success(_) => secondFuture.deleteEntity(entity)
case Failure(e) => throw new Exception(e.getMessage)
}
// the first future alters a table, drops a column
// the second future deletes a row from another table
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如果第一个 future 成功执行,第二个可能会失败。我想恢复第一个未来的更新。我听说过 SQL 事务,似乎是这样的,但是如何呢?
val futuresResult = for {
first <- firstFuture.dropColumn(tableName)
second <- secondFuture.deleteEntity(entity)
} yield (first, second)
Run Code Online (Sandbox Code Playgroud)
一个for-comprehension是在我的情况好多了,因为我没有这两个期货之间的依赖关系,可以并行执行,但这不解决我的问题,结果可能是(成功,成功)或(失败,成功)的例子。
scala future concurrent-processing for-comprehension playframework
Angular 6 使用 Angular Material,显示列表,使用选项卡进入项目详细信息“页面”。
我的路线很简单:
{
path: '', component: CurrenciesComponent
}
Run Code Online (Sandbox Code Playgroud)
我尝试了这样的事情:
{
path: 'currencies',
canActivate: [AuthGuard],
component: CurrenciesComponent,
children: [
{ path: 'currencies/:id', component: CurrenciesDetailComponent }
]
}
Run Code Online (Sandbox Code Playgroud)
我寻找解决方案,但没有解决它。也许使用材质选项卡无法实现这一点?
到目前为止,当主题是 dbContext 时,我在任何可能的地方都使用了异步方法。但是,为了更新实体,我不知道异步方法并使用UpdateRange(用于实体列表)。
现在,我发现BulkUpdateAsync(实体),我没有看到这两种方法之间有很大的区别,它接受 IEnumerable 列表,而 UpdateRange 接受 IEnumerable。
因为每次使用版本后都使用await context.SaveChangesAsync,所以有必要使用BulkUpdateAsync吗?
关于 .Net Core 3 和 EF Core 3