我有一個使用linq從Visit表獲取信息的每個循環。這是嵌套另一個對於每個在第一列得到一個名稱列表循環:離開循環時ForEach錯誤
Caregiver | week1 | week2|....
__________|_______|______|....
John Smith| 2 | 3 |....
Mary Jones| 0 | 1 |....
它去9周,並拿起一個「訪問」中的嵌套循環計數。我相信,當我離開內部循環時,它會在外部循環中最後一個看護人員到達時給我一個NULL錯誤,並且在下一週(第2周)從最上一行再次出現問題。
在根據我的Linq「訪問」查詢Visit表之前,我在Select
語句上得到一個InvalidOperationException。我能做些什麼來解決這個問題?
編輯:以下是錯誤的圖像: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++;
}
對不起,但那不是C! – 2013-02-20 16:29:33
你可以發佈錯誤消息的詳細信息嗎? – GrandMasterFlush 2013-02-20 16:31:58
@MikyDinescu我在帖子後面更新了標籤,謝謝。 – Markpelly 2013-02-20 16:33:27