title: Entity framework mapping enum : The specified value is not an instance of type 'Edm.Int32' Parameter name: value
body: <p>I'm trying to return the result of a entity framework query into my own dto class, at the same time as mapping my enum TradeType.</p>
  
  <p>I'm getting the following error</p>
  
  <p><strong>The specified value is not an instance of type 'Edm.Int32' Parameter name: value</strong></p>
  
  <p>Any idea how to fix or a workaround?</p>
  
  <p>Thanks</p>
  
  <pre><code>public IEnumerable&lt;Trade&gt; GetLiveTrades(string routeName)
  {
      return _entities.Price.Where(p =&gt; p.StatusCode.Equals("A") &amp;&amp; p.Period.PeriodYear &lt;= DateTime.Now.Year+1 &amp;&amp; p.Route.RouteCode.Equals(routeName)).
          Select(p =&gt; new Trade
                          {
                              Volume = (long) (p.Volume ?? 100), 
                              TradeType = (p.PriceTypeCode.Equals("O") ? TradeType.Seller : TradeType.Bidder),
                              Price = p.Price1,
                              TenorStartDate = p.Period.PeriodStartDate.Value,
                              TenorEndDate = p.Period.PeriodStartDate.Value,
                              TradeId = p.ID
                          }).ToList();
          }
  
  public class Trade
  {
      public long Volume { get; set; }
      public TradeType TradeType { get; set; }
      public double Price { get; set; }
      public DateTime TenorStartDate { get; set; }
      public DateTime TenorEndDate { get; set; }
      public Guid TradeId { get; set; }
  }
  </code></pre>