我只想将 2 个参数传递给控制器并运行我的 sql 函数尝试并在没有运气的情况下搜索了很多资源,
谁能给我一些提示?
基本上我遵循这个Web API 和 OData-传递多个参数
当我使用builder.Function
编译器时,请告诉我没有找到扩展方法。
包配置
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="EntityFramework.Functions" version="1.4.0" targetFramework="net452" />
<package id="Microsoft.AspNet.OData" version="6.0.0" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.OData" version="5.3.1" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net452" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net452" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
<package id="Microsoft.OData.Core" version="7.0.0" targetFramework="net452" />
<package id="Microsoft.OData.Edm" version="7.0.0" targetFramework="net452" />
<package id="Microsoft.Spatial" version="7.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" />
<package id="System.Spatial" version="5.6.0" targetFramework="net452" />
</packages>
我的 WebApiConfog.cs
using Microsoft.OData.Edm;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Web.Http;
using System.Web.Http.OData.Builder;
using System.Web.Http.OData.Extensions;
using wcod;
using wcod.Model;
namespace wcod
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
ODataModelBuilder builder = new ODataConventionModelBuilder();
// config.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// var json = config.Formatters.JsonFormatter;
// builder.EntitySet<Booking>("Bookings");
builder.EntitySet<LiveBooking>("LiveBookings");
builder.EntitySet<TimeMarker>("TimeMarkers");
builder.EntitySet<BookingInfo>("BookingInfoes");
builder.EntitySet<LiveBookingByType>("LiveBookingByTypes");
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapODataServiceRoute("odata", "odata/v4", builder.GetEdmModel());
// config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: "odata/v4", model: builder.GetEdmModel());
}
}
}