title: How to use AutoMapper to map a DataRow to an object in a WCF service?
body: <p>I have a WCF service that calls a stored procedure and returns a DataTable. I would like to transform the DataRows to custom object before sending to the consumer but can't figure out how to do so. Lets say I retrieved a customer from a stored procedure. To keep things short here is the customer via DataRow:</p>
  
  <pre><code>string lastName = dt.Rows[0]["LastName"].ToString();
  string firstName = dt.Rows[0]["FirstName"].ToString();
  string age = System.Convert.ToInt32(dt.Rows[0]["Age"].ToString());
  </code></pre>
  
  <p>I can retrieve the customer easily. Now, I created a Customer object like so:</p>
  
  <pre><code>public Customer
  {
       public string LastName {get;set;}
       public string FirstName {get;set;}
       public int Age {get;set;}
  }
  </code></pre>
  
  <p>I loaded AutoMapper from the package manager console. I then put a public static method on my customer like so:</p>
  
  <pre><code>public static Customer Get(DataRow dr)
  {
       Mapper.CreateMap&lt;DataRow, Customer&gt;();
       return Mapper.Map&lt;DataRow, Customer&gt;(dr);
  }
  </code></pre>
  
  <p>When I step through my code, every property in the customer returned from Get() is null. What am I missing here? Do I have to add a custom extension to map from a DataRow? Here is a <a href="https://stackoverflow.com/questions/4759611/map-rowdatacollection-to-dto-using-automapper">thread that seems related</a> but I thought AutoMapper would support this out of the box especially since the property names are identical to the column names. Thanks in advance.</p>