2013-01-11 108 views
0

我的linq查詢返回下面的重複記錄,我如何在這個linq查詢中使用不同的關鍵字。linq查詢中不同的關鍵字

var draft_recieved = from df in _DataContext.tblDrafts 
        from dfBody in _DataContext.DraftBodies 
        from sendUser in _DataContext.tblSends 

        where (df.DraftId == dfBody.DraftID) && (df.DraftId == sendUser.DraftId) && 
        (sendUser.ToEmailId == (Guid)Membership.GetUser().ProviderUserKey) 
        select new 

        { 
         subject = dfBody.Subject, 
         draftid = df.DraftId 
        }; 

回答

0

.Distinct()必須作爲擴展方法應用。

var draft_recieved = (from df in _DataContext.tblDrafts 
       from dfBody in _DataContext.DraftBodies 
       from sendUser in _DataContext.tblSends 

       where (df.DraftId == dfBody.DraftID) && (df.DraftId == sendUser.DraftId) && 
       (sendUser.ToEmailId == (Guid)Membership.GetUser().ProviderUserKey) 
       select new 

       { 
        subject = dfBody.Subject, 
        draftid = df.DraftId 
       }).Distinct(); 
+0

啊,這很糟糕,但感謝回答將不得不使用它。 –