title: I am trying to fill a Customer Model with rows from a datatable
body: <p>I am trying to fill a Customer Model with rows from a datatable but have not been able to get the syntax correct. The original code was taken from this tutorial <a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api" rel="nofollow">Your First ASP.NET Web API (C#</a>).</p>
  
  <p>I have added a DataTable to a Controller but I have not been able to figure out how to get the rows from the table into my Customer Model. I thoought I could do it with a foreach but as I said I can't get the syntax correct. This is what I have</p>
  
  <pre><code>    Customer[] customers = new Customer[]
      {
          //new Customer {Id = "123", FirstName = "Buk", LastName = "Hix" }
          // Replace hard coded customer information with foreach loop.
  
          //commented out because it causes compile warnings
          //foreach (DataRow row in GetAllData().Rows)
          //{
          //    yield return new Customer
          //    {
          //        CustomerId = Convert.ToString(row["CustomerId"]),
          //        FirstName = Convert.ToString(row["FirstName"]),
          //        LastName = Convert.ToString(row["LastName"])
          //    };
          //}
      };
  
      public IEnumerable&lt;Customer&gt; GetAllCustomers()
      {            
          return customers;
      }  
  </code></pre>
  
  <p>What is the best way to accomplish what I am trying to do?</p>