我遇到了一个有趣的问题,EF6,我一生都无法解决。我遇到无法立即加载的实例,并返回一个空列表。但是,如果重新处理相同的项目,则不会出现问题。这使调试变得很困难,因为我无法在同一数据库项上重现该问题。
我尝试了各种加载方式(如注释的代码所示),但似乎没有任何效果。具体来说,l_procedure_x_practice的列表计数为0
context.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
context.Configuration.LazyLoadingEnabled = false;
var query = context.c_queue
.Include(x => x.l_practice)
.Include(x => x.l_procedure)
.Include(x => x.l_procedure.l_procedure_x_practice)
.Include(x => x.l_procedure.l_procedure_x_cpt_code)
.Include(x => x.l_procedure.l_procedure_x_cpt_code.Select(y => y.l_cpt_code.l_cpt_code_x_practice))
.Where(x => x.practice_code == practice.practice_code && x.processed_flag == "N")
.OrderBy(x => x.queue_key)
.Take(25)
.Select(x => x);
//query.Include(x => x.l_practice).Load();
//query.Include(x => x.l_procedure).Load();
//query.Include(x => x.l_procedure.l_procedure_x_practice).Load();
//if (practice.cpt_generated_rvu_flag == "Y")
//{
// query.Include(x => x.l_procedure.l_procedure_x_cpt_code).Load();
// query.Include(x => x.l_procedure.l_procedure_x_cpt_code.Select(y=>y.l_cpt_code.l_cpt_code_x_practice)).Load();
//}
queue = query.ToList();
context.Database.CurrentTransaction.Commit();
日志:
2019-06-06 10:42:13,210 [16] ERROR
Queue Key: 6694177
Practice Code: ABC
Procedure Code: 123456
Practice Null - False;
Procedure Null - False;
l_procedure_x_practice Null - False
l_procedure_x_practice - 0
因此对于上述项目,由于l_procedure_x_practice为0(我专门对此进行了检查),因此引发了错误。我将处理设置回“ N”,该项目处理正常。我确认l_procedure_x_practice表中有数据。