使用 EF 获取 mvc 3 中匹配的行数
我有一个使用 EF 的 mvc 3 应用程序。在一个函数中,我需要获取与语句匹配的行数。我想我可以这样做:
Dim _ClassCount As Integer = _CurrRegistrants.Where(Function(c) c.tues_class = _CurrCourse.course_ref).Count
但是即使有 40 条记录符合条件,它仍然保持在 0..我想我的想法是正确的,我只需要稍微改变一下语法..任何人都知道这是在哪里失败?
Dim _CurrRegistrants As List(Of reg_classes) = db.reg_classes.ToList
For Each Course In _courses.Where(Function(a) a.course_day = "Tuesday")
Dim _CurrCourse As cours = Course
Dim _ClassCount As Integer = _CurrRegistrants.Where(Function(c) c.tues_class = _CurrCourse.course_ref).Count
I have a mvc 3 app that uses EF. In one function I need to get a count of rows that match a statement. I thought I could just do it like this:
Dim _ClassCount As Integer = _CurrRegistrants.Where(Function(c) c.tues_class = _CurrCourse.course_ref).Count
But that stays at 0 even when there are 40 records that match the criteria.. I think I have the right idea I just need to change the syntax a little.. Anyone know where this is failing?
Dim _CurrRegistrants As List(Of reg_classes) = db.reg_classes.ToList
For Each Course In _courses.Where(Function(a) a.course_day = "Tuesday")
Dim _CurrCourse As cours = Course
Dim _ClassCount As Integer = _CurrRegistrants.Where(Function(c) c.tues_class = _CurrCourse.course_ref).Count
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从代码的第一个示例来看,您可能是从数据上下文以外的其他地方提取数据。将数据上下文添加到您的查询中,然后您应该能够访问您尝试相互比较的记录。
From looking at the first example of the code it appears that you might be pulling data from somewhere other than the data context. Add the data context to your query and you should then be able to access to records which you are attempting to compare each other to.