Consume Odata Service and get result in JSON

后端 未结 2 1961
生来不讨喜
生来不讨喜 2020-12-10 17:05

I am consuming odata service using DataServiceContext and want to return data in json format.

I am looking something like this: Odata Query with DataServiceContext

2条回答
  •  一生所求
    2020-12-10 17:44

    You can call context.Format.UseJson method without providing a parameter if you load your service model inside OnContextCreated partial method as shown in the code below:

    public partial class DemoService
    {
        partial void OnContextCreated()
        {
            this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance;
        }
    }
    

提交回复
热议问题