2017-09-05 145 views
1

我正在使用ASP.NET实体框架,并且正在尝试创建一个SqlQuery,但我得到此错误:SQL和ASP.NET指定的从物化“System.Int64”类型转换为“System.Int32”类型无效

The specified cast from a materialized 'System.Int64' type to the 'System.Int32' type is not valid.

我的问题是我不知道哪列给我麻烦,以及如何解决它。这是我的代码。我不认为它是我的演员,因为那些是弦乐。

return View(db.Data.SqlQuery("SELECT ROW_NUMBER() OVER(ORDER BY slotOrder ASC) AS id, 
           concat(a.dateSlot, ' - ', a.timeSlot) as dateSlot, 
           concat(a.dateSlot, '-', a.timeSlot) as timeSlot, 
           COUNT(*) as slotOrder 
           FROM Appointments a 
           LEFT OUTER JOIN dateTimeSlots b 
           ON a.dateSlot = b.dateSlot AND a.timeSlot = b.timeSlot 
           GROUP BY a.dateSlot, a.timeSlot, b.slotOrder 
           ORDER BY b.slotOrder").ToList()); 

这里是我的类:

public class dateTimeSlots 
{ 
    public int id { get; set; } 
    [DisplayName("Date")] 
    public string dateSlot { get; set; } 
    [DisplayName("Time")] 
    public string timeSlot { get; set; } 
    [DisplayName("Order")] 
    public int slotOrder { get; set; } 
} 
+0

什么是模型类哟存储到?请添加它。 'id'或'slotOrder'都是长整型,而不是整数。可能是'id' –

+0

对我的问题添加了类。 – user979331

回答

2

你上面的查询返回Int64long),你是把它作为一个Int32int)。找出它的哪些数字字段并调整模型。

我的猜测是idlong,因为它是ROW_NUMBER()

0

ROW_NUMBER()返回bigintMSDN),它在C#中转换为Int64long

相关问题