linq查询中的不同关键字

时间:2013-01-11 17:27:35

标签: linq

我的linq查询返回如下所示的重复记录,我如何在此linq查询中使用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
                     };

1 个答案:

答案 0 :(得分: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();