【发布时间】:2014-07-24 07:01:18
【问题描述】:
我正在开发一个 Asp.Net MVC 应用程序,其中我有一个包含五列的 SQL 视图,并且我有以下模型
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; }
}
SQL 视图
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<r2.i and r1.term!=r2.term
GO
当我打开应该从上述 SQL 视图呈现数据的页面时。它只是给我一个InvalidOperationException
<m:type>System.InvalidOperationException</m:type>
<m:stacktrace/>
<m:internalexception>
<m:message>
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'.
</m:message>
我尝试将属性设置为 int32,但仍然遇到同样的问题。
【问题讨论】:
-
另外,
int只是 System.Int32 的 C# 别名。与long相同 - 它是 System.Int64 等的别名。因此int和System.Int32可以互换使用。
标签: c# sql sql-server asp.net-mvc sql-view