title: Azure Mobile Service for Windows Phone 8.1 - Insert to existing DB
body: <p>I am writing an app that has an Azure database. I've never did nything connected with Azure, so I am new to all the stuff. I've found on the internet and at microsoft documentation some tutorials, but I must have got sth wrong, cause it doesn't work. So I have a table at my database called Week, I've created a model in my code:  </p>
  
  <pre><code>[DataContract]
  public class Week
  {
      //[JsonProperty(PropertyName = "Id")]
      //[DataMember]
      public int Id { get; set; }
  
      [JsonProperty(PropertyName = "Book")]
      [DataMember]
      public Book CurrentBook { get; set; }
  
      [JsonProperty(PropertyName = "Is_Read")]
      [DataMember]
      public Boolean IsRead { get; set; }
  
      [JsonProperty(PropertyName = "Pages_Read")]
      [DataMember]
      public int PagesRead { get; set; }
  
      [JsonProperty(PropertyName = "Start_Date")]
      [DataMember]
      public DateTime StartDate { get; set; }
  
      [JsonProperty(PropertyName = "User")]
      [DataMember]
      public User Reader { get; set; }
  
      [JsonProperty(PropertyName = "Week_Number")]
      [DataMember]
      public int WeekNumber { get; set; }
  
      public Week(Book currentBook, Boolean isRead, int pagesRead, DateTime startDate, User reader, int weekNumber)
      {
          CurrentBook = currentBook;
          IsRead = isRead;
          PagesRead = pagesRead;
          StartDate = startDate;
          Reader = reader;
          WeekNumber = weekNumber;
      }
  
      public Week()
      {
  
      }
  
      public int GetMonth()
      {
          //TODO: Implement the method.
          return 0;
      }
  }
  </code></pre>
  
  <p>Then I created the WeekRepository for CRUD operations: </p>
  
  <pre><code>public class WeekRepository : BaseRepository&lt;Week&gt;
  {
      private IMobileServiceTable&lt;Week&gt; weekTable;
  
      public string errorMesage = string.Empty;
  
      public WeekRepository()
      {
          weekTable = MobileService.GetTable&lt;Week&gt;();
      }
  
  
      public async override Task&lt;int&gt; Save(Week entity)
      {
          try
          {
              await weekTable.InsertAsync(entity);
              //    .ContinueWith(t =&gt;
              //{
              //    if (t.IsFaulted)
              //    {
              //        errorMesage = "Insert failed";
              //    }
              //    else
              //    {
              //        errorMesage = "Inserted a new item with id " + entity.Id;                       
              //    }
              //});
          }
          catch (WebException ex)
          {
              errorMesage = ex.Message;
          }
          return entity.Id;
      }
  
      public override void Update(Week entity)
      {
          return;
      }
  
      public override Week Load(int bookId)
      {
          var week = weekTable.Where(w =&gt; w.IsRead == false).ToListAsync();
          return week.Result.Single();
      }
  
      public override List&lt;Week&gt; LoadByUserId(int userId)
      {
          return new List&lt;Week&gt;();
      }
  
      public Week LoadCurrentWeek(int userId)
      {
          return new Week();
      }
  }
  </code></pre>
  
  <p>To test if it works, I wrote a simple test:</p>
  
  <pre><code> [TestMethod]
      public void ShouldSaveWeekToTheDB()
      {
          //ARANGE
          Week weekTestEntity = new Week(null, false, 10, new DateTime(), null, 1);
  
          //ACT
          int id = weekRepository.Save(weekTestEntity).Result;
  
          //ASSERT
          var savedItem = weekRepository.Load(1);
          Assert.AreEqual(false, savedItem.IsRead);
      }
  </code></pre>
  
  <p>However, InsertAsync() throws an exception - Not Found. I've no idea what I am doing wrong, cause it seems a simple thing as far as I can see from the material on the Internet.</p>
  
  <p>If You could help me, I would be really grateful!
  Thank You in advance!</p>
  
  <p>Best Regards,
  Roman.</p>