Error while expanding in DataServiceQuery in OData Client

I am testing OData.Net Client as follows:

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(); } 

And I get an exception

"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."

I also tested the same service from a browser using

 http://localhost:6851/Orders(1)?$expand=OrderDetails 

Then the service returns

 { "@odata.context":"http://localhost:6851/$metadata#Orders/$entity","OrderId":1,"CustomerId":"KKKK9","OrderDetails":[ { "OrderDetailId":1,"OrderId":1,"ProductId":1,"UnitPrice":10.00,"Quantity":1 }, { "OrderDetailId":2,"OrderId":1,"ProductId":2,"UnitPrice":20.00,"Quantity":2 }, { "OrderDetailId":6,"OrderId":1,"ProductId":3,"UnitPrice":30.00,"Quantity":33 } ]} 

Fiddler also writes the same json data to the client program, but client modules do not read and do not throw an exception.

If I remove expand, it works fine.

What am I doing wrong?

+4
source share

All Articles