Remove Duplicate Titles from list in MVC

This question already has an answer here:

  • LINQ's Distinct() on a particular property 17 answers

  • First note it is likely that you have duplicates in your database, so maybe you should simply delete them there in the first place.

    If you are sure that you want to remove duplicates from the result of your query, then depending on how you MediaRating class looks like, you can use Linq's Distinct method or DistictBy from MoreLinq (or from John Skeet's post).

    Note that Distinct method might reorder your elements (it depends on Linq provider's implementation), so you should call it before sorting. On the other hand, you can use John Skeet's DistinctBy before .Take(5) to get appropriate results since it is guaranteed to preserve the order of elements.

    链接地址: http://www.djcxy.com/p/51304.html

    上一篇: 我如何使用Linq获取按属性过滤的独特结果

    下一篇: 从MVC列表中删除重复标题