简体   繁体   English

Simple.Data Lazy Reference Null

[英]Simple.Data Lazy Reference Null

I'm querying a table (Jobs) that has 3 records. 我正在查询具有3条记录的表(作业)。 The table has a Foreign Key to JobTypes and to a table called Users. 该表具有JobTypes和名为Users的表的外键。 When running the following query I get three records back, but I can only lazy load for the first returned result. 运行以下查询时,我会获得三条记录,但是我只能延迟加载第一个返回的结果。

IEnumerable<dynamic> jobs = _db.Jobs.All()
            .Where(_db.Jobs.Completed == false)
            .Where(_db.Jobs.RunAfter <= DateTime.Now);

Console.Out.WriteLine("Jobs Found: {0}", jobs.ToList().Count);

foreach(var job in jobs.ToList())
{
    Console.Out.WriteLine("{0} from {1}", job.JobType.Name, job.User.Username); 
}

The output is: 输出为:

Jobs Found: 3
Some Job by admin

And the error message is: Cannot perform runtime binding on a null reference 错误消息是:无法对空引用执行运行时绑定

At the time of the error, using quickwatch job.JobType and job.User are both null but the job.JobType_Id and job.User_Id properties both have a valid guid as a value. 在发生错误时,使用quickwatch job.JobType和job.User均为null,但是job.JobType_Id和job.User_Id属性都具有有效的GUID作为值。

The error occurs on the second iteration in the foreach loop. 错误发生在foreach循环的第二次迭代中。 All jobs currently have the same user id but a different job type id. 当前,所有作业都具有相同的用户ID,但作业类型ID不同。 I have verified the ids are correct in each table. 我已验证ID在每个表中都是正确的。 Any ideas of what could be causing this error during lazy loading? 关于在延迟加载期间可能导致此错误的原因有什么想法?

您是否尝试在配置文件中添加MultipleActiveResultSets = true

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

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