title: c# - Enum description to string with AutoMapper
body: <p>I'm trying to project from my <code>Order</code> model to my <code>OrderDTO</code> model. <code>Order</code> has an enum. The problem is that projection doesn't work if I try to to get the <em>Description</em> attribute from the Enum. Here it's my code:</p>
  
  <ul>
  <li><p><strong>OrderStatus.cs</strong>:</p>
  
  <pre><code>public enum OrderStatus {
      [Description("Paid")]
      Paid,
  
      [Description("Processing")]
      InProcess,
  
      [Description("Delivered")]
      Sent
  }
  </code></pre></li>
  <li><p><strong>Order.cs</strong>:</p>
  
  <pre><code>public class Order {
      public int Id { get; set; }
      public List&lt;OrderLine&gt; OrderLines { get; set; }
      public OrderStatus Status { get; set; }
  }
  </code></pre></li>
  <li><p><strong>OrderDTO.cs</strong>:</p>
  
  <pre><code>public class OrderDTO {
      public int Id { get; set; }
      public List&lt;OrderLineDTO&gt; OrderLines { get; set; }
      public string Status { get; set; }  
  }
  </code></pre></li>
  </ul>
  
  <p>With this following configuration in my <strong>AutoMapper.cs</strong>:</p>
  
  <pre><code>cfg.CreateMap&lt;Order, OrderDTO&gt;().ForMember(
      dest =&gt; dest.Status,
      opt =&gt; opt.MapFrom(src =&gt; src.Status.ToString())
  );
  </code></pre>
  
  <p>Projection works, but I get an <strong>OrderDTO</strong> object like this:</p>
  
  <pre><code> - Id: 1
   - OrderLines: List&lt;OrderLines&gt;
   - Sent //I want "Delivered"!
  </code></pre>
  
  <p>I don't want <code>Status</code> property to be "Sent", I want it to be as its associated <em>Description</em> attribute, in this case, "Delivered".</p>
  
  <p>I have tried two solutions and none of them have worked: </p>
  
  <ol>
  <li>Using <em>ResolveUsing</em> AutoMapper function as explained <a href="https://stackoverflow.com/questions/30711134/automapper-enum-description-attribute">here</a>, but, as it's stated <a href="https://github.com/AutoMapper/AutoMapper/issues/2334#issuecomment-332191644" rel="noreferrer">here</a>:</li>
  </ol>
  
  <blockquote>
    <p>ResolveUsing is not supported for projections, see the wiki on LINQ projections for supported operations.</p>
  </blockquote>
  
  <ol start="2">
  <li><p>Using a static method to return the <em>Description</em> attribute in String by Reflection.</p>
  
  <pre><code>cfg.CreateMap&lt;Order, OrderDTO&gt;().ForMember(
      dest =&gt; dest.Status,
      opt =&gt; opt.MapFrom(src =&gt; EnumHelper&lt;OrderStatus&gt;.GetEnumDescription(src.Status.ToString()))
  );
  </code></pre></li>
  </ol>
  
  <p>But this gives me the following error:</p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method 'System.String
    GetEnumDescription(System.String)' method, and this method cannot be
    translated into a store expression.</p>
  </blockquote>
  
  <p>Then, how can I achieve this?</p>