0

I am having an issue when I rune a RestSharp request on my api. The content response that I am getting is an empty array. Any idea as to why this would by empty when I try and send the values to my model? (It seemed to work fine when I ran a get user, I think it may have to do with using an IEnumerable)

Here is my RestSharp request:

var request = new RestRequest("/problems/", Method.GET);
request.AddHeader("id-header", id);
request.RequestFormat = DataFormat.Json;

var response = client.Execute(request) as RestResponse;

List<MyModel> d = JsonConvert.DeserializeObject<List<MyModel>>(response.Content);

return View(d);

Here is my method in my API:

[ResponseType(typeof(ProblemModel))]
public IQueryable<ProblemModel> GetProblems()
{
    var problems = User.Companies
                       .SelectMany(c => c.Projects)
                       .SelectMany(p => p.Problems)
                       .AsQueryable<Problem>()
                       .Select(factory.AsProblemModel);

    return problems;
}

And My Model the RestSharp is using:

public class MyModel
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public Nullable<int> AssignedToId { get; set; }
    public int ProjectId { get; set; }
}
1
  • Make sure that you tag your questions correctly. You're not just using RestSharp, you're also using JSON.Net. Commented Apr 5, 2014 at 22:33

1 Answer 1

1

I don't know about restSharp, but it would look more natural for GetDefects() to return an IEnumerable instead of an IQueryable

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.