title: Database is throwing an InvalidOperationException status of 500 in a MVC Web Application while accessing data from an SQL View
body: <p>I am working on an Asp.Net MVC Application in which I have an SQL View with five columns and I have the following model for it</p>
  
  <pre><code>public class InferredBid
      {
          public int Id { get; set; }
          public string Market { get; set; }
          public string Term { get; set; }
          public string Bid { get; set; }
          public string Offer { get; set; }
      }
  </code></pre>
  
  <p>SQL View</p>
  
  <pre><code>Create VIEW [dbo].[InferredBids]
  AS
  with numbered as
  (
      select id, product, grade, term, bid, offer, termid, row_number() OVER (Partition BY Product, Grade ORDER BY termid) i
      from  dbo.CanadianCrudes
  )
  
  select r1.i as Id, r1.product + '/' + r1.grade as Market, r1.term + '/' + r2.term as Term, r1.Bid - r2.Offer [Bid], r1.Offer - r2.Bid [Offer] 
  from numbered r1 join numbered r2 on  r1.product = r2.product and r1.grade = r2.grade and r1.termid+1=r2.termid and r1.i&lt;r2.i and r1.term!=r2.term          
  
  
  GO
  </code></pre>
  
  <p>When I open the page that should render the data from the above SQL view. It just threw me an <code>InvalidOperationException</code></p>
  
  <pre><code>&lt;m:type&gt;System.InvalidOperationException&lt;/m:type&gt;
  &lt;m:stacktrace/&gt;
  &lt;m:internalexception&gt;
  &lt;m:message&gt;
  The 'Id' property on 'InferredBid' could not be set to a 'Int64' value. You must set this property to a non-null value of type 'Int32'.
  &lt;/m:message&gt;
  </code></pre>
  
  <p>I tried setting the property to int32 but still I have the same issue.</p>