安装OData环境:
Install-Package Microsoft.AspNet.Odata
安装EF环境:
Install-Package EntityFramework
Code First连接字符串:web.config中
<connectionStrings> <add name="ProductsContext" connectionString="Data Source=.;Initial Catalog=OData2;Persist Security Info=True;User ID=sa;Password=123" providerName="System.Data.SqlClient" /> </connectionStrings>
配置路由:WebApiConfig
config.Count().OrderBy().Select().Filter().Expand().MaxTop(null); ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<student>("student"); builder.EntitySet<score>("score"); builder.EntitySet<course>("course"); builder.EntitySet<teacher>("teacher"); config.MapODataServiceRoute( routeName: "odata", routePrefix: "odata", model: builder.GetEdmModel());