简体   繁体   English

如何使用异步-在ASP.NET MVC 5中等待

[英]How to use async - await in asp.net mvc 5

I am very new in async programming. 我是异步编程的新手。 and i am working on project where i have to use async await method pattern. 我正在研究必须使用异步等待方法模式的项目。 For that I have created a method in my repository project 为此,我在存储库项目中创建了一个方法

    public async Task<IEnumerable<InventoryProductMaster>> GetInventoryProducts(long OrganizationMasterID)
    {
        return await _msbmInventoryDbContext.Set<InventoryProductMaster>().Where(a => a.OrganizationMasterID == OrganizationMasterID);
    }

And i want to use the result of this function into my controller methods. 我想将此函数的结果用于我的控制器方法。

    [HttpGet]
    public async Task<ActionResult> Create()
    {
        long organizationMasterID = Convert.ToInt64(System.Web.HttpContext.Current.Session["LoggedInOrganizationMasterID"]);
        var _materialTypeEntity = await _inventoryUnitOfWork.InventoryProductMasters.GetInventoryProducts(organizationMasterID).ToListAsync();
        return View();
    }

Showing me error message : 'IQueryable' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IQueryable' could be found (are you missing a using directive or an assembly reference?) 向我显示错误消息 :'IQueryable'不包含'GetAwaiter'的定义,并且找不到扩展方法'GetAwaiter'接受类型为'IQueryable'的第一个参数(您是否缺少using指令或程序集引用?)

Please help me. 请帮我。 thanks in advance 提前致谢

public async Task<IEnumerable<InventoryProductMaster>> GetInventoryProducts(long OrganizationMasterID)
{
   return await _msbmInventoryDbContext.Set<InventoryProductMaster>().Where(a => a.OrganizationMasterID == OrganizationMasterID).ToListAsync();
}

You will have to use this method and call can happen like this 您将必须使用此方法,并且调用可能会像这样发生

var _materialTypeEntity = await GetInventoryProducts(cpount);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM