タグリスト:
List<TagObj> tags = new List<TagObj>()
{
new TagObj() { Id = 1, QuestionId = 1, Tag = "news" },
new TagObj() { Id = 2, QuestionId = 1, Tag = "sports" },
new TagObj() { Id = 3, QuestionId = 1, Tag = "famous" },
new TagObj() { Id = 4, QuestionId = 2, Tag = "news" },
new TagObj() { Id = 5, QuestionId = 2, Tag = "sports" },
new TagObj() { Id = 6, QuestionId = 3, Tag = "news" },
new TagObj() { Id = 7, QuestionId = 4, Tag = "funny" },
};
質問リスト:
List<QuestionObj> questions = new List<QuestionObj>()
{
new QuestionObj(){ QuestionId = 1, Question = "Whats up footballers?" },
new QuestionObj(){ QuestionId = 2, Question = "These are famous news?" },
new QuestionObj(){ QuestionId = 3, Question = "Read all about it?" },
new QuestionObj(){ QuestionId = 4, Question = "You know whats funny?" }
};
これらの要求からの着信タグです:
var incomingTags = new List<string>() { "news", "sports" };
これらは、クエリされています
var query = from t in tags
join q in questions on t.QuestionId equals q.QuestionId
where incomingTags.Contains(t.Tag)
select new { question = q, tag = t };
var result = query.
GroupBy(g => g.question.QuestionId).
Where(g => g.ToList().Select(l => l.tag.Tag).SequenceEqual(incomingTags)).
Select(s => s.First().question).ToList();
出典
2017-10-12 10:07:26
Rob
Anyの代わりにAllを使用しようとしましたか? – Rob
はい - Anyの代わりにAllを使用すると、1単語以上入力すると結果が表示されません。 – MadsBinger
KDB_questionsとKDB_tagsのモデルについてもう少し詳しくお聞かせください。 – Rob