title: RavenDB Transformation - Exception thrown on transforming Id
body: <p>I am trying to run a RavenDB transform, but I'm running into the following exception:</p>
  
  <blockquote>
    <p>Raven.Imports.Newtonsoft.Json.JsonSerializationException: Could not read value for property: Id ---> System.FormatException: Input string was not in a correct format.</p>
  </blockquote>
  
  <p>I assume this is because my models use integer Ids rather than strings. How can I get the transform to work with ints?</p>
  
  <p><strong>DiscountCode_ViewModel.cs</strong></p>
  
  <pre><code>public class DiscountCode_ViewModel : AbstractTransformerCreationTask&lt;DiscountCode&gt;
  {
      public DiscountCode_ViewModel()
      {
          TransformResults = discounts =&gt; discounts
              .Select(discount =&gt; new SimpleDiscountCode
              {
                  // Throws an exception here
                  Id = discount.Id,
                  MerchantId = discount.MerchantId,
                  TermsAndConditions = discount.TermsAndConditions,
                  Code = discount.Code,
                  Description = discount.Description
              });
      }
  }
  </code></pre>
  
  <p><strong>DiscountCode.cs</strong></p>
  
  <pre><code>public class DiscountCode
  {
      public int Id { get; set; }
      public int MerchantId { get; set; }
      public string Description { get; set; }
      public string Code { get; set; }
      public string TermsAndConditions { get; set; }
  
      public DateTime StartDate { get; set; }
      public DateTime EndDate { get; set; }
      public int SortOrder { get; set; }
  
      // a bunch more properties...
  }
  </code></pre>
  
  <p><strong>SimpleDiscountCode.cs</strong></p>
  
  <pre><code>public class SimpleDiscountCode
  {
      public int Id { get; set; }
      public int MerchantId { get; set; }
      public string Title { get; set; }
      public string Code { get; set; }
      public string TermsAndConditions { get; set; }
  }
  </code></pre>
  
  <p><strong>DiscountCode_ByMerchantId.cs</strong></p>
  
  <pre><code>public class DiscountCodes_ByMerchantId : AbstractIndexCreationTask&lt;DiscountCode&gt;
  {
      public DiscountCodes_ByMerchantId()
      {
          Map = discounts =&gt; discounts
              .Select(discount =&gt; new
              {
                  discount.MerchantId,
                  discount.StartDate,
                  discount.EndDate,
                  discount.SortOrder
              });
  
          Sort(x =&gt; x.SortOrder, SortOptions.Int);
      }
  }
  </code></pre>
  
  <p><strong>Query.cs</strong></p>
  
  <pre><code>var discounts = await session
                  .Query&lt;DiscountCode, DiscountCodes_ByMerchantId&gt;()
                  .Include&lt;DiscountCode, Merchant&gt;(d =&gt; d.MerchantId)
                  .Where(x =&gt; x.MerchantId == id)
                  .Where(x =&gt; x.StartDate &lt;= DateTime.Now &amp;&amp; x.EndDate &gt;= DateTime.Now)
                  .OrderBy(x =&gt; x.SortOrder)
                  .TransformWith&lt;DiscountCode_ViewModel, SimpleDiscountCode&gt;()
                  .ToListAsync();
  
  var merchant = await session.LoadAsync&lt;Merchant&gt;(id);
  </code></pre>
  
  <p>Stack Trace</p>
  
  <blockquote>
    <p>Raven.Imports.Newtonsoft.Json.JsonSerializationException occurred
      HResult=-2146233088
      Message=Could not read value for property: Id
      Source=Raven.Abstractions
      StackTrace:
           at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 2015
           at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 434
           at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 180
           at Raven.Imports.Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 732
           at Raven.Client.Document.SessionOperations.QueryOperation.DeserializedResult[T](RavenJObject result) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 262
           at Raven.Client.Document.SessionOperations.QueryOperation.Deserialize[T](RavenJObject result) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 190
           at Raven.Client.Document.SessionOperations.QueryOperation.b__26_0[T](RavenJObject x) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 139
           at System.Linq.Enumerable.SelectListIterator<code>2.ToList()
           at Raven.Client.Document.SessionOperations.QueryOperation.Complete[T]() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 138
           at Raven.Client.Document.AsyncDocumentQuery</code>1.d__118.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\AsyncDocumentQuery.cs:line 1230
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Raven.Client.Document.AsyncDocumentQuery<code>1.&lt;ToListAsync&gt;d__110.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\AsyncDocumentQuery.cs:line 1157
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter</code>1.GetResult()
           at TCB.MerchantService.Data.MerchantRepository.d__3.MoveNext() in C:\GitCode\TCB.MerchantService\src\TCB.MerchantService.Data\MerchantRepository.cs:line 64
      InnerException: 
           HResult=-2146233033
           Message=Input string was not in a correct format.
           Source=System.Private.CoreLib
           StackTrace:
                at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
                at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
                at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
                at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
                at Raven.Abstractions.Json.JsonNumericConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\Builds\RavenDB-Stable-3.5\Raven.Abstractions\Json\JsonNumericConverter.cs:line 36
                at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 1769
                at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 900
                at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 2005
           InnerException: </p>
  </blockquote>
  
  <p>Fiddler Request</p>
  
  <blockquote>
    <p>POST /queries HTTP/1.1
    Host: localhost:8080
    Connection: keep-alive
    Content-Length: 16
    Accept: application/json, text/javascript, <em>/</em>; q=0.01
    Origin: <a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a>
    X-Requested-With: XMLHttpRequest
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    Content-Type: application/json; charset=UTF-8
    Referer: <a href="http://localhost:8080/studio/index.html" rel="nofollow noreferrer">http://localhost:8080/studio/index.html</a>
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-US,en;q=0.8
    Cookie: _ga=GA1.1.1952671077.1488191167</p>
  </blockquote>