C# L2S调用在尝试检索实体时导致有关int的null赋值的异常

C# L2S调用在尝试检索实体时导致有关int的null赋值的异常,c#,linq-to-sql,exception,C#,Linq To Sql,Exception,我有以下代码 public JsonResult GetRequestDetails(int id) { TestRequest req = _context.TestRequests.Where(x => x.id == id).Single(); 函数还有更多内容,但第一行是我得到以下异常的地方: The null value cannot be assigned to a member with type System.Int32 which is

我有以下代码

    public JsonResult GetRequestDetails(int id)
    {
        TestRequest req = _context.TestRequests.Where(x => x.id == id).Single();
函数还有更多内容,但第一行是我得到以下异常的地方:

The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
现在在调试器中,我可以看到
id
是一个有效的整数,对于我正在进行的调用,它等于5atm。然后我转到SQL并验证是否存在id值为5的记录。我尝试将
Single()
更改为
First()
,但异常消息很可能是错误的,并且存在多条记录,但发生了相同的异常

我完全搞不懂为什么这个linq-to-sql调用失败了。

如果问题是“没有得到一行”,那么错误就不同了

这里的问题在于materialiser,即将从
IDataReader
检索到的数据行转换为对象。我强烈怀疑行上的int列之一是
null
,但在DBML中,is被标记为不可为null


找到这是哪一列,并在DBML中使其为空或从数据库中删除空。

是的,就是这样!我的一个int字段被标记为“Nullable:false”,而它本不应该被标记。