0
我该如何在linq中实现类似的东西。在我的linq代码中,答案userID不等于问题用户标识,它会得到最佳答案。这是假设筛选用户选择自己的帖子作为最佳答案。如果用户选择自己的答案作为最佳答案,那么它必须至少提升3次。Linq:其中x = 1除非y> 3
var AwardedAnswers = from u in context.userinfo
select new
{
u.user_userid,
u.user_username,
u.user_GravatarHash,
Answers = from ans in context.post
let QuestionUserID = (from q in context.post
where q.post_id == ans.post_parentid
select new
{
q.userinfo.user_userid
}).FirstOrDefault()
where ans.userinfo.user_userid == u.user_userid
&& !object.Equals(ans.post_parentid, null)
&& ans.post_isselected == true
//this is where my trouble is
//this filters answers made by the original poster
//This should filter unless the Vote count is higher then 2
&& (ans.userinfo.user_userid != QuestionUserID.user_userid)
select new
{
ans.post_id,
ans.post_parentid
}
};
我希望你的例子不是现实世界的代码,因为它看起来很难维护。由于LINQ推迟执行,我建议将查询分解为更小的部分,以便维护起来更容易一些。 – Kane 2010-02-08 07:15:07