小编Jas*_*ell的帖子

我为什么要使用IHttpActionResult而不是HttpResponseMessage?

我一直在使用WebApi进行开发,并已转移到WebApi2,其中Microsoft引入了一个IHttpActionResult似乎建议用于返回a 的新接口HttpResponseMessage.我对这个新接口的优点感到困惑.这似乎主要是公正提供SLIGHTLY更简单的方法来创建一个HttpResponseMessage.

我认为这是"为抽象而抽象"的论点.我错过了什么吗?除了节省一行代码之外,使用这个新接口可以获得什么样的真实优势?

旧方式(WebApi):

public HttpResponseMessage Delete(int id)
{
    var status = _Repository.DeleteCustomer(id);
    if (status)
    {
        return new HttpResponseMessage(HttpStatusCode.OK);
    }
    else
    {
        throw new HttpResponseException(HttpStatusCode.NotFound);
    }
}
Run Code Online (Sandbox Code Playgroud)

新方式(WebApi2):

public IHttpActionResult Delete(int id)
{
    var status = _Repository.DeleteCustomer(id);
    if (status)
    {
        //return new HttpResponseMessage(HttpStatusCode.OK);
        return Ok();
    }
    else
    {
        //throw new HttpResponseException(HttpStatusCode.NotFound);
        return NotFound();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# httpresponse asp.net-web-api

312
推荐指数
6
解决办法
19万
查看次数

WebAPI和WebAPI 2之间有什么区别

现在随Visual Studio 2013提供的WepApi和WepApi2之间的主要差异(我应该关注的是什么)?

.net c# asp.net-web-api

54
推荐指数
3
解决办法
4万
查看次数

如何获取任务的结果或返回值?

有人可以向我解释如何返回任务的结果吗?我目前正在尝试执行以下操作,但我的任务不会返回我期望的列表吗?这里有什么问题?

static void Main()
{
    List<Task> tasks = new List<Task>();
    List<string> sha256_hashes = new List<string>();
    List<string> results = new List<string>();

    sha256_hashes.Add("hash00");
    sha256_hashes.Add("hash01");
    sha256_hashes.Add("hash03");
    foreach(string sha256 in sha256_hashes)
    {
        string _sha256 = sha256;
        var task = Task.Factory.StartNew(() => GetAdditionalInfo(_sha256));
        tasks.Add(task);
    }
    Task.WaitAll(tasks.ToArray());
   //I want to put all the results of each task from tasks but the problem is
   //I can't use the Result method from the _task because Result method is not available
   //below is my plan to get all the …
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library

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

为什么QtGUI不包含Qt 5中的所有GUI元素

我看了VoidRealm教程,他很容易包含QtGui并开始使用它!但我做同样的事情,它对我不起作用!例如我的代码在我包含QLabel之前不知道QWidget!或所有其他Gui元素......

#include <QApplication>
#include <QtGui>
#include <QtCore>

int main(int argc, char *argv[])
{

    QApplication a(argc, argv);
    QWidget *win = new QWidget;
    win->setWindowTitle("MBS");

    QGridLayout *gLay = new QGridLayout;

    QLabel *label1 = new QLabel("Name: ");

    win->show();

    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

c++ qt qt5

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

如何解决SQL Server中的性能问题

我有一个相对较大的数据库(每个表有数百万条记录),它有许多表和索引,这些表和索引是由以前的开发人员设置的,我正在努力找到解决一些性能问题的好方法.

我们的应用程序在其整个生命周期中进行了许多数据库调用,我试图找到一种很好的方法来诊断一些较慢的查询,或者我们缺少索引的一些实例,或者我们写入的表上有索引的索引.

有哪些快速查询可以让我对我正在寻找的内容有所了解?

sql sql-server sql-server-2008

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