title: ASP.NET Web API returns empty collection in json response
body: <p>OK, I have a problem with the ASP.NET Web API. I followed <a href="http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-entity-framework/using-web-api-with-entity-framework,-part-1" rel="nofollow" title="this">this</a> tutorial on how to create it. I mdified the tutorial for my purposes.</p>
  
  <p>I have a patch class which has a Collection of download URLs. The API is returning every information just fine, only the collection of DownloadURLs is returned as null. 
  However when I stepped through the code step by step debugging it, it returned the collection properly.
  What did I do wrong. I'm not able to find my error.
  Here is the Model:</p>
  
  <pre><code>public class Patch
  {
      [Key]
      [Required]
      [JsonProperty("PatchVersion")]
      public string PatchVersion { get; set; }
  
      [Required]
      [JsonProperty("Length")]
      public long Length { get; set; }
  
      [JsonProperty("VersionToUpdateFrom")]
      public string VersionToUpdateFrom { get; set; }
  
      [JsonProperty("DownloadUris")]
      public ICollection&lt;DownloadUri&gt; DownloadUris { get; set; }
  }
  
  public class DownloadUri
  {
      [Key]
      [Required]
      [JsonProperty("AbsolutePath")]
      public string AbsolutePath { get; set; }
  
      [Required]
      [JsonProperty("IndirectDownload")]
      public bool IndirectDownload { get; set; }
  }
  </code></pre>
  
  <p>This is my DataContext class:</p>
  
  <pre><code>public class PatchesContext : DbContext
  {
      public PatchesContext()
          : base("name=PatchesContext")
      {
      }
  
      public DbSet&lt;Patch&gt; Patches { get; set; }
  
      public DbSet&lt;DownloadUri&gt; DownloadUris { get; set; }
  }
  </code></pre>
  
  <p>This is the ContextInitializer</p>
  
  <pre><code>public class PatchesContextInitializer : DropCreateDatabaseIfModelChanges&lt;PatchesContext&gt;
  {
      protected override void Seed(PatchesContext context)
      {
  
          var downloadUri = new List&lt;DownloadUri&gt;
          {
              new DownloadUri
              {
                  AbsolutePath = "http://downloadUri1.test", IndirectDownload = false
              },
              new DownloadUri
              {
                  AbsolutePath = "http://downloadUri2.test", IndirectDownload = false
              }
          };
  
          var patches = new List&lt;Patch&gt;
          {
              new Patch
              {
                  Length = 100000, PatchVersion = "1.0.0.0", VersionToUpdateFrom = string.Empty, DownloadUris = downloadUri
              },
              new Patch
              {
                  DownloadUris = null, Length = 10000, PatchVersion = "1.1.0.0", VersionToUpdateFrom = "1.0.0.0"
              }
          };
          patches.ForEach(p =&gt; context.Patches.Add(p));
          context.SaveChanges();
      }
  }
  </code></pre>
  
  <p>And finally here is my controller class. I left out the Post, Put and Delete Methods, because I didn't test them yet (no point if get is not working):</p>
  
  <pre><code>public class AdminController : ApiController
  {
      private PatchesContext db = new PatchesContext();
  
      // GET api/Admin
      public IEnumerable&lt;Patch&gt; GetPatches()
      {
          return db.Patches.AsEnumerable();
      }
  
      // GET api/Admin/5
      public Patch GetPatch(string version)
      {
          Patch patch = db.Patches.Find(version);
          if (patch == null)
          {
              throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
          }
  
          return patch;
      }
  }
  </code></pre>
  
  <p>I hope you all can help me and thanks.</p>
  
  <p>/edit: 
  The Header looks like this:</p>
  
  <pre><code>Status Code: 200 OK
  Cache-Control: no-cache
  Content-Length: 291
  Content-Type: application/json; charset=utf-8
  Date: Fri, 25 Oct 2013 17:25:48 GMT
  Expires: -1
  Pragma: no-cache
  Server: Microsoft-IIS/8.0
  X-SourceFiles: =?UTF-8?B?RTpcVXNlcnNcUm9iZXJ0XERvY3VtZW50c1xWaXN1YWwgU3R1ZGlvIDIwMTJcUHJvamVjdHNcTjQ0V2Vic2l0ZVxONDRXZWJzaXRlXGFwaVxhZG 1pbg==?=
  </code></pre>
  
  <p>The Response Body looks like this:</p>
  
  <pre><code>[
  
    {
      "$id": "1",
      "PatchVersion": "1.0.0.0",
      "Length": 100000,
      "VersionToUpdateFrom": "",
      "DownloadUris": null
    },
    {
      "$id": "2",
      "PatchVersion": "1.1.0.0",
      "Length": 10000,
      "VersionToUpdateFrom": "1.0.0.0",
      "DownloadUris": null
    }
  ]
  </code></pre>