views:

96

answers:

1

how do I implement something like this in linq. In my linq code it gets the best answers where the answer userID does not equal the Question userid. This is suppose to filter users picking their own post as best answer. If the user picked their own answer as best answer then it must be upvoted at least 3 times.

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
                               }

                      };
+1  A: 

How about:

 && (ans.userinfo.user_userid != QuestionUserID.user_userid
     || ans.upvotes >= 3)

That's just a guess though - we don't know what your database structure is like around votes.

Jon Skeet
@Downvoter: Any particular reason?
Jon Skeet