0

I'm using a UnitOfWork function to get items from my db like this:

var items = UnitOfWork.ConversationPosts.Query(postFilter).Take(10);

However, is there a way to get the first 10 unique items? I tried using a Linq function like this but I don't know how to use it properly:

var items= UnitOfWork.ConversationPosts.Query(postFilter).Take(10).Where(x =>x.id ___);
DannyD
  • 2,732
  • 16
  • 51
  • 73
  • what column(s) should be unique? – maxlego May 14 '13 at 22:58
  • I just need the id column to be unique. not the whole element. Thanks – DannyD May 14 '13 at 23:02
  • umm.. shouln't the id to be unique by itself? if it's not the primary key then you should use grouping. – maxlego May 14 '13 at 23:04
  • thanks maxlego. The id is actually not the primary key in this instance. Could explain how I can group my items? – DannyD May 14 '13 at 23:06
  • if you use group by, then you cant select the whole row. you get aggregated valeues (min, max, sum ..) and values grouped by. So we need to know what is the result that you want – maxlego May 14 '13 at 23:08

1 Answers1

0
var items = UnitOfWork.ConversationPosts
              .Query(postFilter)
              .GroupBy(c => c.Id)
              .Select(d => d.First())
              .Take(10);
devlish
  • 76
  • 5