开发者

How can I get distinct records from many to many relationship using Linq to Sql

For brevity, let's say I have the following 3 tables (m:n): Articles, Topics and a joining table ArticleTopic. I need to get the top n articles for n topics. Each article should only show once for the entire result set.

Article: -Id -Title

Topic: -Id -Name

ArticleTopic: -Id -ArticleId -TopicId

Thanks for your 开发者_Python百科help!


topics
   .SelectMany(topic => topic.ArticleTopic)
   .Select(articleTopic => article)
   .Distinct()

But it is not obvious to me what you mean by top n - I can not see any ranking information in your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜