My team and I are working on a project with OData. We are trying to use the RestSharp client but cannot find any clean example of a best practice on using it with OData in C#.
The issue we are having is that when trying to get the data it is 2 layers of JSON we think.
private T execRequest<T>(RestClient client, RestRequest request, bool retry = true)
{
IRestResponse response;
T resultdata = default(T);
try
{
response = client.Execute(request);
}
catch (Exception)
{
throw;
}
if (response.StatusDescription == "OK") // TAKE CARE OF Session expired or invalid
{
resultdata = JsonConvert.DeserializeObject<T>(response.Content);
}
return resultdata;
}
In this result if we use a simple Type like Person (ID,enabled,active) we see the data in response.content.
"{\"@odata.context\":\"http://localhost:56460/$metadata#Person\",\"value\":[{\"ID\":1090,\"enabled\":true,\"active\":false}]}"
However resultdata does not actually get the data...it initializes the object but ID, enabled and active are 0, false, false.
We are fairly new to this...my feeling though is that since the response back is not 100% the json data might be the issue?
(p.s. also looking for a some doc's pertaining to OData and RESTSharp).
edit: We are thinking that we need to deserialize to a higher level object since the data in response.content is an object, then the object per say. We are trying to find a clean example of this with OData but have not yet.