DoI*_*oIt 3 c# sql sql-server asp.net-mvc sql-view
我正在开发一个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; }
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
当我打开应该从上面的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>
Run Code Online (Sandbox Code Playgroud)
我尝试将属性设置为int32但仍然有同样的问题.
将代码更改为以下内容,因为SQL似乎返回long该字段的Int64(相当于C#).
public class InferredBid
{
public long Id { get; set; }
public string Market { get; set; }
public string Term { get; set; }
public string Bid { get; set; }
public string Offer { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2925 次 |
| 最近记录: |