2013-10-07 38 views
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(); 

當我執行此查詢,Distinct()不起作用。它選擇內部查詢結果中的所有記錄。如何修改它以在內部查詢結果中獲得不同的行。獨特的不能在LINQ嵌套選擇工作

+1

「UserId」,「NotificationTypeId」和「ItemId」是什麼類型? –

+1

UserId,NotificatioTypeId和ItemId是否會再次類似於第一行?如此清晰可見三者的獨特組合。 –

+0

UserId,NotificationTypeId是int not null,itemId是int null –

回答

0

您可以通過此使用組,如下因素代碼可以幫助你解決這個問題,

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

讓我知道如果u有任何問題。