0

我的 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
                     };
4

1 回答 1

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();
于 2013-01-11T17:40:55.510 回答