Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 异步从Mongo获取用户产品_C#_Asp.net_Mongodb - Fatal编程技术网

C# 异步从Mongo获取用户产品

C# 异步从Mongo获取用户产品,c#,asp.net,mongodb,C#,Asp.net,Mongodb,我正在尝试创建一种方法,可以获得用户的产品。已经有一个可以返回与提供的id匹配的产品 public async Task<IActionResult> GetProduct(string productId) { try { var product = await _productService.GetProductAsync(productId); if

我正在尝试创建一种方法,可以获得用户的产品。已经有一个可以返回与提供的id匹配的产品

public async Task<IActionResult> GetProduct(string productId)
        {
            try
            {
                var product = await _productService.GetProductAsync(productId);
                if (product != null)
                    return Ok(product);
                _logger.LogWarning($"Could not find product : {productId}");
                return NotFound(new ApiError(ErrorCode.NotFound, "Could not find product"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error retrieving product : {productId}");
                return StatusCode((int)HttpStatusCode.InternalServerError, new ApiError(ErrorCode.ServerError, "Internal server error", "Please contact developer"));
            }
        }
公共异步任务GetProduct(字符串productId) { 尝试 { var product=await\u productService.GetProductAsync(productId); 如果(产品!=null) 返回Ok(产品); _logger.LogWarning($“找不到产品:{productId}”); return NotFound(新的APIRROR(ErrorCode.NotFound,“找不到产品”); } 捕获(例外情况除外) { _logger.LogError(例如,$“检索产品时出错:{productId}”); 返回状态码((int)HttpStatusCode.InternalServerError,新ApiError(ErrorCode.ServerError,“内部服务器错误”,“请与开发人员联系”); } }
我需要怎么做才能获得用户产品?我试了很多,但没有结果。

欢迎。我建议您在发布第一个问题之前,花点时间阅读并理解在上解释的内容以及您在注册新帐户时真正应该了解的其他内容。你给我们的只是一段现有的代码,实际上你自己的解释与你所问的问题完全无关。阅读材料后考虑修改。具体地说。没有对结构或预期结果的描述,我们也没有坐在您的办公桌旁,因此我们无法访问您的数据外观或您的期望,除非您向我们展示。如果你想回答一个问题,那么你需要提供尽可能多的信息来解决它。目前的“问题”没有这些。