小编Car*_*d87的帖子

净核心错误名称“ Ok”在当前上下文中不存在

我收到以下错误:当前上下文中不存在名称'Ok'。

如何在Controller API中解决此问题?Return Ok已经嵌入在控制器中。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using Newtonsoft.Json;
using WeatherTest.Models;

namespace WeatherChecker.Controllers
{

    public class WeatherData
    {
        [HttpGet("[action]/{city}")]
        public async Task<IActionResult> City(string city)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri("http://api.openweathermap.org");
                    var response = await client.GetAsync($"/data/2.5/weather?q={city}&appid=YOUR_API_KEY_HERE&units=metric");
                    response.EnsureSuccessStatusCode();

                    var stringResult = await response.Content.ReadAsStringAsync();
                    var rawWeather = JsonConvert.DeserializeObject<OpenWeatherResponse>(stringResult);

                    // Error Here: ** The name 'Ok' does not exist in the current context **
                    return Ok(new
                    { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

5
推荐指数
1
解决办法
3105
查看次数

在MVC程序中调用Web API

我创建了Web API以从OpenWeatherAPI接收每日温度.

现在我想在我的MVC网页上显示所有内容.我把API调用放在了MVC项目中; 计划稍后创建新项目以获得更好的微服务架构.

我在Debug窗口和MVC html中看到这些错误,如下所示.如何在html上显示天气,温度等,降水量.

Debug: weathercontroller.City("Seattle")    The function evaluation requires all threads to run.    System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult>"

HTML: System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[Microsoft.AspNetCore.Mvc.IActionResult,WeatherChecker.Controllers.WeatherController+<City>d__0]"
Run Code Online (Sandbox Code Playgroud)

MVC页面:

namespace WeatherPage.Controllers
{
    public class HomeController : Controller
    {

        public WeatherController weathercontroller = new WeatherController();

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";
            ViewData["test"] =  weathercontroller.City("Seattle");
            return View();
        }
Run Code Online (Sandbox Code Playgroud)

API控制器:

[Route("api/[controller]")] 
public class WeatherController : ControllerBase
{
    [HttpGet("[action]/{city}")]
    public async Task<IActionResult> City(string city)
    {

        Rootobject rawWeather = new Rootobject();
        using (var …
Run Code Online (Sandbox Code Playgroud)

c# dotnet-httpclient asp.net-core-mvc asp.net-core asp.net-core-webapi

2
推荐指数
1
解决办法
347
查看次数

使用LinqPad进行SQL性能调优

我是DBA和软件工程师,负责管理SQLServer 2016企业数据库.Application Sql是用EntityFramework而不是Stored过程编写的.

DBA是否应该在Linqpad中将团队的EF查询放入开发中的性能调整?我上周了解了LinqPad,并惊讶于它如何将Linq查询转换为SQL.有时Linq查询是不可预测/随机的(MS仍在进行产品改进).这样,我不必等待随机查询在暂存或生产中命中SQLServer Profiler.我可以在sprint开发期间调整应用程序开发人员.

这是性能调优的合适策略吗?我读了很多sql博客,但没有人讨论LinqPad策略.只是询问这是否有助于性能调优方法.

sql-server performance entity-framework sql-server-2016

0
推荐指数
1
解决办法
102
查看次数