title: Return the correct structure of a model using the stored procedure?
body: <p>I have a stored procedure:</p>
  <pre><code>ALTER PROCEDURE FindPolicyByService
      @codes varchar(200)
  AS 
  BEGIN
      SELECT 
          dbo.DXBusinessPolicy_Policy.Code AS PolicyCode,
          dbo.DXBusinessPolicy_Policy.Name AS PolicyName,
          dbo.DXBusinessPolicy_Service.Code AS ServiceCode,
          dbo.DXBusinessPolicy_Service.Name AS ServiceName
      FROM 
          dbo.DXBusinessPolicy_Policy 
      JOIN
          dbo.DXBusinessPolicy_PolicyService ON dbo.DXBusinessPolicy_Policy.ID = dbo.DXBusinessPolicy_PolicyService.PolicyID
      JOIN
          dbo.DXBusinessPolicy_Service ON dbo.DXBusinessPolicy_PolicyService.ServiceID = dbo.DXBusinessPolicy_Service.ID
      WHERE 
          dbo.DXBusinessPolicy_Service.Code IN (SELECT value FROM STRING_SPLIT(@codes, ','))
  END
  
  EXEC FindPolicyByService &quot;ott,cmr&quot;
  </code></pre>
  <p>The result when I execute it:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th></th>
  <th>PolicyCode</th>
  <th>PolicyName</th>
  <th>ServiceCode</th>
  <th>ServiceName</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>COMBO.2103002</td>
  <td>Giá nền combo T04.2021</td>
  <td>CMR</td>
  <td>Camera</td>
  </tr>
  <tr>
  <td>2</td>
  <td>COMBO.2103002</td>
  <td>Giá nền combo T04.2021</td>
  <td>OTT</td>
  <td>OTT</td>
  </tr>
  <tr>
  <td>3</td>
  <td>COMBO.2103003</td>
  <td>Combo T5.2021</td>
  <td>CMR</td>
  <td>Camera</td>
  </tr>
  <tr>
  <td>4</td>
  <td>COMBO.2103003</td>
  <td>Combo T5.2021</td>
  <td>OTT</td>
  <td>OTT</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>but I want to return the result when executing the model structure as follows in C#:</p>
  <pre><code>namespace DXBusinessPolicy.Data.Model
  {
      public class PolicyViewModel
      {
          public string PolicyCode { get; set; }
          public string PolicyName { get; set; }
          public List&lt;ServiceViewModel&gt; Services { get; set; }
      }
  
      public class ServiceViewModel
      {
          public string ServiceCode { get; set; }
          public string ServiceName { get; set; }
      }
  }
  </code></pre>
  <p>Example:</p>
  <pre><code>{
     PolicyCode: &quot;COMBO.2103002&quot;,
     PolicyName: &quot;Giá nền combo T04.2021&quot;,
     Services: [
                   { ServiceCode: &quot;CMR&quot;, ServiceName: &quot;Camera&quot; }, 
                   { ServiceCode: &quot;OTT&quot;, ServiceName: &quot;OTT&quot;} 
               ]
  }, 
  {
     PolicyCode: &quot;COMBO.2103003&quot;,
     PolicyName: &quot;Combo T5.2021&quot;,
     Services: [
                   { ServiceCode: &quot;CMR&quot;, ServiceName: &quot;Camera&quot; }, 
                   { ServiceCode: &quot;OTT&quot;, ServiceName: &quot;OTT&quot; }
               ]
  }
  </code></pre>
  <p>I don't know if there is a way to do it when I call this stored procedure, or is it possible only in C#?</p>