繁体   English   中英

SQL和ASP.NET从实例化的“ System.Int64”类型到“ System.Int32”类型的指定强制转换无效

[英]SQL and ASP.NET The specified cast from a materialized 'System.Int64' type to the 'System.Int32' type is not valid

我正在使用ASP.NET实体框架,并且尝试创建SqlQuery,但出现此错误:

从实例化的“ System.Int64”类型到“ System.Int32”类型的指定转换无效。

我的问题是我不知道哪一栏给我带来了麻烦以及如何解决它。 这是我的代码。 我不认为我正在做的演员表是因为这些是琴弦。

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; }
}

上面的查询返回一个Int64long ),并将其存储为一个Int32int )。 找出是哪个数字字段并调整模型。

我的猜测是id longROW_NUMBER()

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM