title: LINQ throwing invalid cast exception on a bigint
body: <p>I have a LINQ query that looks something like this:</p>
  
  <pre><code>var clintLst = (from clntDt in ent.ClientDatas
                  where clntDt.CompanyName.Substring(0,searchWord.Length).Equals(searchWord, StringComparison.CurrentCultureIgnoreCase)
                  orderby clntDt.CompanyName
                  select new { ClientDataID = clntDt.ClientDataID,
                      CompanyName = clntDt.CompanyName, 
                      ContactName = (clntDt.ContactFirstName + " " + clntDt.ContactLastName),
                      CompanyLocation = clntDt.Location.LocationCity.CityName + ", " + clntDt.Location.LocationState.StateCode
                  } ).Distinct().Take(10);
  </code></pre>
  
  <p>However, it is throwing the following exception:</p>
  
  <blockquote>
    <p>The specified cast from a materialized
    'System.Int32' type to the
    'System.Int64' type is not valid. [..]
    Exception Details:
    System.InvalidOperationException: The
    specified cast from a materialized
    'System.Int32' type to the
    'System.Int64' type is not valid.</p>
    
    <p>Source File:
    C:\TempPersonalCode\TransportTracking\TransportTracking\TransportTracking\Controllers\AJAXController.cs
    Line: 35</p>
  </blockquote>
  
  <p>(Line 35 is the select clause)</p>
  
  <p>I'm confused because if change:</p>
  
  <pre><code>select new { ClientDataID = clntDt.ClientDataID,
      CompanyName = clntDt.CompanyName, 
  </code></pre>
  
  <p>to</p>
  
  <pre><code>select new { ClientDataID = (Int32)clntDt.ClientDataID,
      CompanyName = clntDt.CompanyName, 
  </code></pre>
  
  <p>then it works fine. Isn't an anonymous object supposed to use reflection to determine it's type? if so, why is it deciding that it's an "Int32" instead of a long? Within the EDMX I have it as an Int64.</p>