Linq: Dove x = 1 A meno che y> 3
-
19-09-2019 - |
Domanda
Come faccio a implementare qualcosa di simile in LINQ. Nel mio codice LINQ ottiene le migliori risposte in cui la risposta userID non è uguale al userid domanda. Questo è supponiamo di filtrare gli utenti raccogliendo il proprio posto come migliore risposta. Se l'utente selezionato la propria risposta come migliore risposta allora deve essere upvoted almeno 3 volte.
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
}
};
Soluzione
Come su:
&& (ans.userinfo.user_userid != QuestionUserID.user_userid
|| ans.upvotes >= 3)
Questa è solo una supposizione però - non sappiamo che cosa il vostro struttura del database è come intorno voti
.Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow