title: Returning wrong list. Can I return the other?
body: <p>Okay, I have a gridview in my WPF application. I use MVVM and C#. The gridview is filled with data.
  I call the data using a web service. I don't communicate with the database directly. And we have set stored procedures, so I can't create my own and use it for the application.</p>
  
  <p>I have 2 tables. MaintenanceCall and MainCallProblems, a child of MaintenanceCall
  MaintenanceCall:</p>
  
  <pre><code>[Intrecno] [bigint] IDENTITY(1,1) NOT NULL,
  [IntrecnoLandObject] [bigint] NULL,
  [CallerName] [varchar](100) NULL,
  [CallerTel] [varchar](20) NULL,
  [CaptureBy] [bigint] NULL,
  [CaptureDate] [datetime] NULL,
  </code></pre>
  
  <p>Intrecno is the PK. IntrecnoLandObject is a FK that I will use to pull the data out.</p>
  
  <p>MainCallProblems:</p>
  
  <pre><code>[Intrecno] [bigint] IDENTITY(1,1) NOT NULL,
  [IntrecnoCallNo] [bigint] NULL,
  [CaptureBy] [bigint] NULL,
  [CaptureDate] [datetime] NULL,
  [ProblemDescription] [varchar](500) NULL,
  </code></pre>
  
  <p>IntrecnoCallNo is the FK that comes from MaintenanceCall.</p>
  
  <p>Basically, a user uses my form to log a complaint/problem on an object. He selects the object, with its ID stored in memory and logs a call. Each call can have many problems. Once they click save, the call is logged. The data is inserted into MaintenanceCall, the object's ID, the user who logged the call and the time. Then the Problem is logged into MainCallProblems, along with the user etc... Just know that all fields are filled out.</p>
  
  <p>Now I have a history gridview on my form. When the user selects the object to log calls on, the history should be loaded, if any.
  This is my problem.</p>
  
  <p>Somewhere in my service code, I placed the wrong list somewhere.
  Lets say that there are 4 MaintenanceCall records. Each MainCall has it's own problem in MainCallProblems. What if one call has 2 problems? This is what I'm stuck with.</p>
  
  <p>My service code to get the list populated and sent back:</p>
  
  <pre><code> public List&lt;MaintenanceCall&gt; GetMaintenance(Dictionary&lt;string, object&gt; propertyValues) //Brings in the selected land object intrecno number
      {
          List&lt;MaintenanceCall&gt; mainCalls = ExecuteDataReader&lt;MaintenanceCall&gt;("spGetMainCall", propertyValues, typeof(MaintenanceCall)); //finds all maintenance calls associated with that land object
          foreach (var instance in mainCalls) //for each specific call
          {
              Dictionary&lt;string, object&gt; paramKey = new Dictionary&lt;string, object&gt;();
              paramKey.Add("IntrecnoCallNo", instance.Intrecno); //now sends the primary key of maintenance call into the child table, MainCallProblems and finds the problems with that key, which is the foreign key 
  
              List&lt;MainCallProblems&gt; problems = ExecuteDataReader&lt;MainCallProblems&gt;("spGetMainCallProblems", paramKey, typeof(MainCallProblems)); //creates a list of the problems associated with that call. can be one or many
  
              foreach (var problem in problems) //for each problem with that call, fill out the data
              {
                  instance.ProblemDesc = problem.ProblemDescription; // the problem description for each problem call
              }
          }
  
          return mainCalls; //returns the first list, with the data now stored
      }
  </code></pre>
  
  <p>As you can see, I get the landobject's ID in the method params. That is used in the stored procedure to retrieve the MaintenanceCall instances. Of which there are 4.</p>
  
  <p>Each call is then broken down to each problem in a call, the first foreach loop. Now the PK of MaintenanceCall is passed into MainCallProblems to find the actual problem.
  Like I said, this list should be 5.
  So the MaintenanceCall list that is returned is missing one record. It fills the data and overwrites one record, because the one list is smaller than the other.</p>
  
  <p>How do I correct this. I can't make the one list the same as the other, I get errors. And I can't return any other list type. </p>
  
  <p>Ideally I want returned:</p>
  
  <p><img src="https://i.stack.imgur.com/NaZXP.png" alt="enter image description here"></p>
  
  <p>As you see, this is just a quick select I wrote in SQL that shows the FK and the problem. 2 problems have the same FK, but in my app, one would be overwritten, and I recieve 4 results instead of 5</p>
  
  <p>If there are any further explinations needed, please let me know and I will edit accordingly.</p>