title: Handling Convertions
body: <p>In vb:</p>
  
  <pre><code>Dim mEmpLeaves As EmployeeLeaves
  mEmpLeaves = EmployeeLeaves.GetEmployeeLeaves(Session("DbConnector"), 
                "dbo.usp_EmployeeWebLeave" &amp; EmployeeId)
  ViewState("Empleave") = mEmpLeaves
  </code></pre>
  
  <p>in a diff function i use this viewstate like :</p>
  
  <pre><code>Dim mEmployeeLeaves As EmployeeLeaves = DirectCast(ViewState("Empleave"), 
                                      EmployeeLeaves)
  Dim mEmployeeLeave As EmployeeLeave = 
                               mEmployeeLeaves.GetEmployeeLeaveById(leaveId)
  </code></pre>
  
  <p>Since I am not using viewstate in my API due to its stateless behaviour and which I have heard is not correct either. How can I achieve this?</p>
  
  <p>What i am doing is </p>
  
  <pre><code>EmployeeLeaves mEmployeeLeaves = DbEntities.Usp_EmployeeWebLeave(EmployeeId)
                                   .FirstOrDefault();
  mEmployeeLeave mEmployeeLeave= mEmployeeLeaves.GetEmployeeLeaveById(LeaveId)
  </code></pre>
  
  <p>also tried:</p>
  
  <pre><code>object Leaves = DbEntities.Usp_EmployeeWebLeave(EmployeeId)
                                   .FirstOrDefault();
  EmployeeLeaves mEmployeeLeaves = (EmployeeLeaves)Leaves;
  EmployeeLeave mEmployeeLeave= mEmployeeLeaves.GetEmployeeLeaveById(LeaveId);
  </code></pre>
  
  <p>I am getting a exception 
  "</p>
  
  <blockquote>
    <p>Unable to cast object type
    'employeeDataAccess.payCare.usp_EmployeeWebLeave_Result' to type
    'HumanResource.Paycare.EmployeeLeaves</p>
  </blockquote>
  
  <p>.</p>
  
  <p>I am not finding a way to cast this. In such scenario vb seems to be so simple. Wasted my whole day behind this. Please if anyone can remove me out of this. Thanks in advance.</p>