我正在使用实体框架。 我有这种情况:
ParentObject - 有一个子集: Child1 。
在表格上我有1个复选框和1个按钮。 我有一个报告显示PArentObject和相应的Child1列表。
该按钮的Onclick事件具有以下代码:
context.Configuration.LazyLoadingEnabled = False
Dim plist as IQueryable(Of ParentObject)
Dim chlist as IQueryable(of Child1)
plist=context.Set(Of ParentObject)
chlist=context.Set(of Child1)
plist.ToList()
chlist=chlist.Where(Function(t1) plist.Any(Function(t2) t2.id=t1.parent))
If checkbox1.checked then chlist=chlist.Where(Function(t1) t1.vl>0)
chlist.ToList()
MyReport.Datasource=plist.ToList
按下按钮时会出现以下结果:
1) With checkbox checked , Press the button ( first time ) - The report display all the Parent , each of them with only the childs that have vl1>0 ( **Correct** )
2) With checkbox unchecked , press the button (second time ) - The report display all the Parent with all the childs ( **Correct** )
3) With checkbox checked , press the button ( third time ) - The report display all the parent with all the childs ( **Not correct** )
我关闭表单,然后重新打开它。
1) With checkbox unchecked , press the button (First time ) - The report display all the Parent with all the childs ( **Correct** )
2) With checkbox checked , press the button ( Second time ) - The report display all the parent with all the childs ( **Not correct** )
为什么我在重复上述示例中的查询时得不到正确的结果? 在这些情况下我该怎么办? 谢谢!