随笔 - 106  文章 - 0  评论 - 1  阅读 - 40962

OData

安装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());
复制代码

 

posted on   段了的弦  阅读(186)  评论(0编辑  收藏  举报
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示