帮助完成简单的 Linq 计数语句
var q = dc.tblHelpCentreQuestions.Where(c => c.userID == UserID);
q.OrderByDescending(c => c.dateSubmitted);
这工作正常,但我还需要返回从 tblHelpCentreReplies
返回的记录数,其中 QuestionID
等于 tblHelpCentreQuestions.ID
。这对于我来说在 SQL 中很简单,有人可以告诉我这是如何在 LINQ to SQL 中完成的吗?
编辑
我已经得到了这样的信息:
var q =
from question in dc.tblHelpCentreQuestions
join replies in dc.tblHelpCentreReplies on question.ID
equals replies.ticketID
where question.userID == UserID
orderby question.dateSubmitted descending
select new { question, replies.Count() };
但是replies.Count()抛出:
无效的匿名类型成员 声明者。匿名类型成员 必须向会员申报 分配、简单名称或成员 访问。
var q = dc.tblHelpCentreQuestions.Where(c => c.userID == UserID);
q.OrderByDescending(c => c.dateSubmitted);
This works fine, but I also need to return the count of records returned from tblHelpCentreReplies
where QuestionID
equals tblHelpCentreQuestions.ID
. This is easy enough for me in SQL, can someone show me how this is done in LINQ to SQL?
Edit
I've got as far as this:
var q =
from question in dc.tblHelpCentreQuestions
join replies in dc.tblHelpCentreReplies on question.ID
equals replies.ticketID
where question.userID == UserID
orderby question.dateSubmitted descending
select new { question, replies.Count() };
But replies.Count() throws:
Invalid anonymous type member
declarator. Anonymous type members
must be declared with a member
assignment, simple name or member
access.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
linq 查询如下所示:
更新
如果你有一个关系映射可能会更容易一些
the linq query would look like this:
update
if you have a relation mapping than that could be a bit easier
这比您想象的要容易:-)
This is easier than you might imagine :-)