title: Empty client-side models
body: <p>I'm working on a Windows Phone 8.1 app, and I'm having trouble getting the client's model objects to obtain their values from the database that I'm hosting on Azure.  The code I've written seems to work (at least iterate correctly), but my problem is that the Bars objects are empty.  I don't know how to get them to obtain the values that are stored in the db (barID, barName, etc).  I've built a working services project that I've published to an Azure website.  This project contains my DTOs, context, and controllers.  My client project contains models and views.  Do I need to change my architecture?  If so, how should I change it?  Here's the code that's being called in my controller:</p>
  
  <pre><code>public class BarsController : ApiController
  {
      private GatoradeShowerDB db = new GatoradeShowerDB();
  
      // GET: api/Bars
     // [Route("http://gatoradeshower.azurewebsites.net/api/bars/All")]
      public IQueryable&lt;Bar&gt; GetBars()
      {
          return db.Bars;
      }
  
      // GET: api/Bars/5
      [ResponseType(typeof(Bar))]
      public async Task&lt;IHttpActionResult&gt; GetBar(int id)
      {
          Bar bar = await db.Bars.FindAsync(id);
          if (bar == null)
          {
              return NotFound();
          }
  
          // return Ok(bar);
          return Ok(bar);
      }
  
      // PUT: api/Bars/5
      [ResponseType(typeof(void))]
      public async Task&lt;IHttpActionResult&gt; PutBar(int id, Bar bar)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          if (id != bar.BarID)
          {
              return BadRequest();
          }
  
          db.Entry(bar).State = EntityState.Modified;
  
          try
          {
              await db.SaveChangesAsync();
          }
          catch (DbUpdateConcurrencyException)
          {
              if (!BarExists(id))
              {
                  return NotFound();
              }
              else
              {
                  throw;
              }
          }
  
          return StatusCode(HttpStatusCode.NoContent);
      }
  
      // POST: api/Bars
      [ResponseType(typeof(Bar))]
      public async Task&lt;IHttpActionResult&gt; PostBar(Bar bar)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          db.Bars.Add(bar);
          await db.SaveChangesAsync();
  
          return CreatedAtRoute("DefaultApi", new { id = bar.BarID }, bar);
      }
  
      // DELETE: api/Bars/5
      [ResponseType(typeof(Bar))]
      public async Task&lt;IHttpActionResult&gt; DeleteBar(int id)
      {
          Bar bar = await db.Bars.FindAsync(id);
          if (bar == null)
          {
              return NotFound();
          }
  
          db.Bars.Remove(bar);
          await db.SaveChangesAsync();
  
          return Ok(bar);
      }
  
      protected override void Dispose(bool disposing)
      {
          if (disposing)
          {
              db.Dispose();
          }
          base.Dispose(disposing);
      }
  
      private bool BarExists(int id)
      {
          return db.Bars.Count(e =&gt; e.BarID == id) &gt; 0;
      }
  }
  </code></pre>
  
  <p>Here's my DTO code:</p>
  
  <pre><code>public partial class Bar
  {
      public int BarID { get; set; }
  
      [Required]
      [StringLength(255)]
      public string BarName { get; set; }
  
      [Required]
      [StringLength(255)]
      public string BarStreet { get; set; }
  
      [Required]
      [StringLength(50)]
      public string BarCity { get; set; }
  
      [Required]
      [StringLength(50)]
      public string BarState { get; set; }
  
      [Required]
      [StringLength(50)]
      public string BarPhone { get; set; }
  
      [Required]
      [StringLength(50)]
      public string BarZip { get; set; }
  }
  </code></pre>
  
  <p>Here's my Context code:</p>
  
  <pre><code>public partial class GatoradeShowerDB : DbContext
  {
      public GatoradeShowerDB()
          : base("name=GatoradeShowerDB")
      {
      }
  
      public virtual DbSet&lt;Bar&gt; Bars { get; set; }
      public virtual DbSet&lt;Event&gt; Events { get; set; }
      public virtual DbSet&lt;Game&gt; Games { get; set; }
      public virtual DbSet&lt;Group&gt; Groups { get; set; }
      public virtual DbSet&lt;Member&gt; Members { get; set; }
      public virtual DbSet&lt;Stadium&gt; Stadia { get; set; }
      public virtual DbSet&lt;Team&gt; Teams { get; set; }
      public virtual DbSet&lt;TeamsTest&gt; TeamsTests { get; set; }
      public virtual DbSet&lt;WatchParty&gt; WatchParties { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Game&gt;()
              .Property(e =&gt; e.GameTime)
              .IsFixedLength();
  
          modelBuilder.Entity&lt;TeamsTest&gt;()
              .Property(e =&gt; e.teamName)
              .IsUnicode(false);
      }
  }
  </code></pre>
  
  <p>Here's the code from my xaml.cs file (view):</p>
  
  <pre><code>public async void GetBars()
  {
      using (var client = new HttpClient())
      {
          barsListBox.Items.Add("using block entered");
          client.BaseAddress = new Uri("http://nflff.azurewebsites.net");
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
          barsListBox.Items.Add("client's defaultrequestheaders done");
  
          HttpResponseMessage response = await client.GetAsync("api/bars");
          barsListBox.Items.Add("httpresponsemessage object created with getasync");
          barsListBox.Items.Add(response.Content.ToString());
  
          if (response.IsSuccessStatusCode)
          {
              barsListBox.Items.Add("if entered");
              IList&lt;Bars&gt; bars = await response.Content.ReadAsAsync&lt;IList&lt;Bars&gt;&gt;();
              //successfully retrieves all bars items but need to format the printing
              //Wait... How can you instantiate a list ... to read itself? (Am I wrong) Nothing is being stored?
              //barsListBox.Items.Add(bars); //this just prints System.Collection.Generic...
              barsListBox.Items.Add(bars.Count); //list contains correct number of items
              for (int i = 0; i &lt; bars.Count; i++)
              {
                  barsListBox.Items.Add("for entered"); //iterating correct number of times
                  barsListBox.Items.Add(i); //when printing bar[i], just prints empty object
              }
                  //foreach (var bar in bars)
                  //{
                  //    barsListBox.Items.Add("foreach entered"); //not entering foreach
                  //    barsListBox.Items.Add(bar.ToString());
                  //}
  
              barsListBox.Items.Add("after foreach loop"); //getting printed
          }
          barsListBox.Items.Add("after if");
      }
  }
  </code></pre>
  
  <p>And here's my (client-side) model's code:</p>
  
  <pre><code>class Bars 
  {
      private int barID { get; set; }
      private string barName { get; set; }
      private string barStreet { get; set; }
      private string barCity { get; set; }
      private string barState { get; set; }
      private string barPhone { get; set; }
      private string barZip { get; set; }
  
      //public Bars()
      //{
      //    //empty constructor
      //}
  
      public override string ToString()
      {
          return "Bar: " + barID.ToString() +" " + barName.ToString() + " Phone: " + barPhone; //model obj not obtaining any values
      }
  }
  </code></pre>
  
  <p>I'm at a complete loss as this is my first time creating a mobile app with a hosted database.  At the moment, I'm getting the correct number of bars items returned from ReadAsAsync call in my view, but they're all empty.  How can I get these Bars objects to contain their proper values?  My database is a SQL database with a .NET back-end hosted on Azure web sites.</p>