将 Request.CreateResponse 转换为 .Net Core 3.1

Convert Request.CreateResponse to .NetCore 3.1

我正在将 webapi 网络框架转换为 netcore 3.1。我需要转换这段代码

Request.CreateResponse(DataSourceLoader.Load(orders, loadOptions));

在 NetCore 3 中,CreateResponse 不是 Request 方法。转换中的完整代码

        [HttpGet]
    public HttpResponseMessage Get(DataSourceLoadOptions loadOptions)
    {
        loadOptions.PrimaryKey = new[] { "OrderID" };

        var orders = from o in _db.Orders
                     select new
                     {
                         o.OrderID,
                         o.CustomerID,
                         CustomerName = o.Customer.ContactName,
                         o.EmployeeID,
                         EmployeeName = o.Employee.FirstName + " " + o.Employee.LastName,
                         o.OrderDate,
                         o.RequiredDate,
                         o.ShippedDate,
                         o.ShipVia,
                         ShipViaName = o.Shipper.CompanyName,
                         o.Freight,
                         o.ShipName,
                         o.ShipAddress,
                         o.ShipCity,
                         o.ShipRegion,
                         o.ShipPostalCode,
                         o.ShipCountry
                     };

        return Request.CreateResponse(DataSourceLoader.Load(orders, loadOptions));
    }

在此先感谢您的帮助。

我假设您想要 return 200 个结果,数据为:

[HttpGet]
public IActionResult Get(DataSourceLoadOptions loadOptions)
{
    loadOptions.PrimaryKey = new[] { "OrderID" };

    var orders = from o in _db.Orders
        select new
        {
            o.OrderID,
            o.CustomerID,
            CustomerName = o.Customer.ContactName,
            o.EmployeeID,
            EmployeeName = o.Employee.FirstName + " " + o.Employee.LastName,
            o.OrderDate,
            o.RequiredDate,
            o.ShippedDate,
            o.ShipVia,
            ShipViaName = o.Shipper.CompanyName,
            o.Freight,
            o.ShipName,
            o.ShipAddress,
            o.ShipCity,
            o.ShipRegion,
            o.ShipPostalCode,
            o.ShipCountry
        };

    return new OkObjectResult(DataSourceLoader.Load(orders, loadOptions));
}