mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2025-02-08 02:39:26 +08:00
Created Async Await (markdown)
parent
852cddf3a7
commit
9b329cf754
49
Async-Await.md
Normal file
49
Async-Await.md
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
|
||||
### 整个项目采用异步的方法:
|
||||
|
||||
比如异步仓储
|
||||
|
||||
```
|
||||
public async Task<TEntity> QueryById(object objId, bool blnUseCache = false)
|
||||
{
|
||||
//return await Task.Run(() => _db.Queryable<TEntity>().WithCacheIF(blnUseCache).InSingle(objId));
|
||||
return await _db.Queryable<TEntity>().WithCacheIF(blnUseCache).In(objId).SingleAsync();
|
||||
}
|
||||
|
||||
```
|
||||
比如异步服务
|
||||
|
||||
```
|
||||
public async Task<TEntity> QueryById(object objId)
|
||||
{
|
||||
return await BaseDal.QueryById(objId);
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
异步接口
|
||||
|
||||
```
|
||||
public async Task<MessageModel<PageModel<Module>>> Get(int page = 1, string key = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
key = "";
|
||||
}
|
||||
int intPageSize = 50;
|
||||
|
||||
var data = await _moduleServices.QueryPage(a => a.IsDeleted != true && (a.Name != null && a.Name.Contains(key)), page, intPageSize, " Id desc ");
|
||||
|
||||
return new MessageModel<PageModel<Module>>()
|
||||
{
|
||||
msg = "获取成功",
|
||||
success = data.dataCount >= 0,
|
||||
response = data
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
Loading…
Reference in New Issue
Block a user