小编Mat*_*hew的帖子

OData Client中DataServiceQuery中的Expand错误

我正在测试OData .Net客户端,如下所示:

static void Main(string[] args)
    {
        var dataServiceContext = new Container(new Uri("http://localhost.fiddler:6851/"));

        var selectedOrders = from order in dataServiceContext.Orders.Expand("OrderDetails")
                                where order.OrderId==1
                                select order;

        DataServiceCollection<Order> orders = new DataServiceCollection<Order>(selectedOrders);        

        // Update Navigation
        orders[0].OrderDetails[0].Quantity=9999;

        dataServiceContext.SaveChanges();
    }
Run Code Online (Sandbox Code Playgroud)

而且,我得到了一个例外

"When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written."

我还通过浏览器测试了相同的服务

http://localhost:6851/Orders(1)?$expand=OrderDetails
Run Code Online (Sandbox Code Playgroud)

然后,服务返回

{ …
Run Code Online (Sandbox Code Playgroud)

expand client json odata

5
推荐指数
1
解决办法
640
查看次数

标签 统计

client ×1

expand ×1

json ×1

odata ×1