我有一个 For each 循环,它使用 linq 从访问表中获取信息。它与另一个 For each 循环嵌套,该循环在第一列中列出一个名称:
Caregiver | week1 | week2|....
__________|_______|______|....
John Smith| 2 | 3 |....
Mary Jones| 0 | 1 |....
它持续 9 周,并在嵌套循环中获取“访问”计数。我相信当我离开内部循环时,当它到达外部循环中的最后一个看护者时,它会给我一个 NULL 错误,并且下周(第 2 周)从顶行再次开始出现问题。
在根据我的 Linq“访问”查询访问表之前,我在语句上收到InvalidOperationException 。Select
我能做些什么来解决这个问题?
编辑:这是错误的图像:http: //i.imgur.com/yztNLR3.png
var phs = from cg in Context.CareGivers
join cgg in Context.CareGiverGroups on cg.car_gvr_int_id equals cgg.car_gvr_int_id
join o in Context.Organizations on cgg.org_int_id equals o.org_int_id
where cg.row_sta_cd.Trim() == "A"
&& cgg.alt_phy_id != null
&& cgg.alt_phy_id.Trim() != String.Empty
&& o.cli_acc_fg.Trim() == "Y"
&& o.org_int_id == 1468461
select cg;
int r = 1;
int s = 1;
for (int i = 0; i < 9; i++)
{
start = start.AddDays(i * -7);
end = start.AddDays(7);
foreach (var cg in phs)
{
// grab the correct exception, this will allow us to figure out where the issue might be
var visits = cg.CareGiverFunction.First(cgf => cgf.CodeDetail.cod_dtl_ds.Trim() == "Family Physician").VisitCareGiver.Select(vcg => vcg.Visit).AsQueryable();
visits = visits.Where(v => v.adm_ts >= start && v.adm_ts < end
&& (v.CodeDetail.cod_dtl_ext_id.Trim() == "I" || v.CodeDetail.cod_dtl_ext_id.Trim() == "V")
&& v.VisitStatusCdCodeDetail.cod_dtl_ext_id.Trim() != "CANCEL");
int counter = visits.Count();
String phys = cg.Person.DisplayName();
workbook.AddCell(r, 0, phys);
workbook.AddCell(r, s, counter);
r++;
}
s++;
}