0
(from SN1 in uow.SystemNotifications
 join sn2 in
      (
            from SN2 in uow.SystemNotifications
            select new { SN2.UserId, SN2.NotificationTypeId, SN2.ItemId }
      ).Distinct()
  on new { SN1.UserId, SN1.NotificationTypeId }
  equals new { sn2.UserId, sn2.NotificationTypeId }
  select SN1).ToList();

When I execute this query, Distinct() is not working. It selects all the records in the result of inner query. How to modify this to get distinct rows in the inner query result.

M.S.
  • 4,283
  • 1
  • 19
  • 42
  • 1
    Of what type are `UserId`, `NotificationTypeId` and `ItemId`? – Konrad Morawski Oct 07 '13 at 08:07
  • 1
    UserId,NotificatioTypeId and ItemId are they coming again similar to first row? As distinct here will find the distinct combination of three. – Incredible Oct 07 '13 at 08:09
  • UserId, NotificationTypeId are int not null and itemId is int null – M.S. Oct 07 '13 at 08:28
  • @Iti- yes, these three columns are repeating multiple times but other columns corresponding to these have different values. – M.S. Oct 07 '13 at 08:30
  • 1
    @Mahesh: Yes this is the reason as distinct here will find the distinct combination and they can be multiple combination. Use Group By. – Incredible Oct 07 '13 at 08:31
  • can you provide the linq query using group by for this situation? – M.S. Oct 07 '13 at 08:36

1 Answers1

0

You can use group by for this, Folowing code helps you to solve this problem,

var rootcategories2 = (from p in sr.products
                               group p.subcategory by p.category into subcats
                               select subcats);

let me know if u have any problem.

Mayur Borad
  • 1,295
  • 9
  • 23