title: Getting inappropriate json data struture
body: <p>I have this data:<strong>Users</strong></p>
  
  <pre><code>UserId   Name
   42      Abc  
   43      Pqr
   44      lmn
   45      xyz
  </code></pre>
  
  <p><strong>Mappings</strong>:</p>
  
  <pre><code>MappingId  User1  User2  
  1           42    43
  2           42    44 
  3           43    44
  </code></pre>
  
  <p>Now i have 1 web service which i fires every seconds to get users and users connection and return json data in this format:</p>
  
  <pre><code>var data =
          [{
              "UserId": 42,
              "Name": "Abc",
              "Connections": [43,44]
          }, {
              "UserId": 43,
              "Name": "Pqr",
              "Connections": [44]
          }, {
              "UserId": 44,
              "Name": "Lmn",
              "Connections": []
          }, {
              "UserId": 45,
              "Name": "xyz",
              "Connections": []
          }];
  </code></pre>
  
  <p>Basically the purpose of this web service is to always fetch new users and new connections of existing users and that is why i am firing this
  web service in each seconds.</p>
  
  <p>So my conditions is like this (skip already fetch users and fetch new users if there) or (skip already fetch connections and fetch new 
  connections of existing users) but json data structure should be same.</p>
  
  <p>So that on each web service call either i get all new users or if new users are not there then fetch existing users whose new connections are made.</p>
  
  <p><strong>Use Case 1</strong>:</p>
  
  <pre><code>UserId   Name
   42      Abc  
   43      Pqr
  </code></pre>
  
  <p><strong>output json</strong>:</p>
  
  <pre><code>var data =
          [{
              "UserId": 42,
              "Name": "Abc",
              "Connections":[]
          },
           {
              "UserId": 43,
              "Name": "xyz",
              "Connections":[]
          }];
  </code></pre>
  
  <p><strong>Use Case 2</strong>:
  If connections are made between user 42 and user 43 then:
  <strong>output json</strong>:</p>
  
  <pre><code>var data =
          [{
              "UserId": 42,
              "Name": "Abc",
              "Connections":[43]
          }];
  </code></pre>
  
  <p><strong>Use Case 3</strong>:New user enters:</p>
  
  <pre><code>UserId   Name
   42      Abc  
   43      Pqr
   44      lmn
  </code></pre>
  
  <p><strong>output json</strong>:</p>
  
  <pre><code>var data =
          [{
              "UserId": 44,
              "Name": "Almn",
              "Connections":[]
          }];
  </code></pre>
  
  <p><strong>Use Case 4</strong>:connections made between user 42 and 44:</p>
  
  <pre><code>var data =
          [{
              "UserId": 42,
              "Name": "Abc",
              "Connections":[42,44]
          }];
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>public HttpResponseMessage GetUsers([FromUri]Int32 skip = 0)    
          {
              var userBll = new UserBLL();
              var result = context.Users.ToList();
              var lists = new List&lt;string&gt;();
              var connectionsData = context.Mappings.ToList().OrderBy(t =&gt; t.CreatedDate.Value.Date).ThenBy(t =&gt; t.CreatedDate.Value.TimeOfDay).Skip(skip).Take(1);
              lists.Add(connectionsData.FirstOrDefault().User1 + "," + connectionsData.FirstOrDefault().User2);
              var response = Request.CreateResponse(HttpStatusCode.OK, result.Select(r =&gt; new 
              {
                  UserId=r.UserId,
                  Name = r.FirstName + " " + r.LastName,
                  Connections = lists
              }));
              return response;
          }
  </code></pre>
  
  <p>But getting below output with below input data:</p>
  
  <pre><code>UserId   Name
   42      Abc  
   43      Pqr
   44      lmn
   45      xyz
  
  
  MappingId  User1  User2  
  1           42    43
  
  var data =
          [{
              "UserId": 42,
              "Name": "Abc",
              "Connections": [42,43]
          }, {
              "UserId": 43,
              "Name": "Pqr",
              "Connections": [42,43]
          }, {
              "UserId": 44,
              "Name": "Lmn",
              "Connections": [42,43]
          }, {
              "UserId": 45,
              "Name": "xyz",
              "Connections": [42,43]
          }];
  </code></pre>
  
  <p>Javascript Code:</p>
  
  <pre><code>var userList = [];
    function GetData() {
               $.getJSON('Url', {skip:userList.length} ,function (response) {
                  updateUserList(response);
              });
          }
  
   function updateUserList(data) {
              if (JSON.stringify(userList).toString() != JSON.stringify(data).toString()) { //if old data is not same as new data
                  userList = data;
              }
              else
              {
                  setTimeout(GetData, 1000); //fire request every 1 seconds
              }
          }
  </code></pre>
  
  <p><strong>Note</strong>:I don't have foreign key relationship.</p>