最新资讯 _LastestItems 调用时排除推荐内容如何实现 悬赏:30

调用 最新资讯 _LastestItems 调用时排除推荐内容

/// <summary>
        /// 依据查询条件获取ContentItem列表
        /// </summary>
        public PagingDataSet<ContentItem> GetContentItems(bool enableCaching, ContentItemQuery query, int pageSize, int pageIndex)
        {
            var sql = Sql.Builder.Select("spb_cms_ContentItems.*").From("spb_cms_ContentItems");
            var whereSql = Sql.Builder;
            var orderSql = Sql.Builder;

            if (query.ContentFolderId.HasValue && query.ContentFolderId.Value > 0)
            {
                if (query.IncludeFolderDescendants.HasValue && query.IncludeFolderDescendants.Value)
                {
                    ContentFolderService contentFolderService = new ContentFolderService();
                    IEnumerable<ContentFolder> contentFolders = contentFolderService.GetDescendants(query.ContentFolderId.Value);

                    IEnumerable<int> descendantFolderIds = contentFolders == null ? new List<int>() : contentFolders.Select(f => f.ContentFolderId);

                    List<int> folderIds = new List<int>(descendantFolderIds);
                    folderIds.Add(query.ContentFolderId.Value);

                    whereSql.Where("spb_cms_ContentItems.ContentFolderId in (@ContentFolderIds)", new { ContentFolderIds = folderIds });
                }
                else
                {
                    whereSql.Where("spb_cms_ContentItems.ContentFolderId=@0", query.ContentFolderId.Value);
                }
            }
            else if (query.ModeratorUserId.HasValue && query.ModeratorUserId.Value > 0)
            {
                ContentFolderService contentFolderService = new ContentFolderService();
                ContentFolderModeratorService contentFolderModeratorService = new ContentFolderModeratorService();
                IEnumerable<int> moderatedFolderIds = contentFolderModeratorService.GetModeratedFolderIds(query.ModeratorUserId.Value);
                List<int> folderIds = new List<int>(moderatedFolderIds);
                if (query.IncludeFolderDescendants.HasValue && query.IncludeFolderDescendants.Value)
                {
                    foreach (var folderId in moderatedFolderIds)
                    {
                        IEnumerable<ContentFolder> contentFolders = contentFolderService.GetDescendants(folderId);
                        IEnumerable<int> descendantFolderIds = contentFolders == null ? new List<int>() : contentFolders.Select(f => f.ContentFolderId);
                        folderIds.AddRange(descendantFolderIds);
                    }
                }
                if (folderIds.Count > 0)
                    whereSql.Where("spb_cms_ContentItems.ContentFolderId in (@ContentFolderIds)", new { ContentFolderIds = folderIds });
            }

            if (query.ContentTypeId.HasValue && query.ContentTypeId.Value > 0)
                whereSql.Where("spb_cms_ContentItems.ContentTypeId=@0", query.ContentTypeId.Value);

            if (query.UserId.HasValue && query.UserId.Value > 0)
                whereSql.Where("spb_cms_ContentItems.UserId=@0", query.UserId.Value);

            if (query.IsContributed.HasValue)
            {
                whereSql.Where("spb_cms_ContentItems.IsContributed=@0", query.IsContributed.Value);
            }

            if (query.IsEssential.HasValue)
            {
                whereSql.Where("spb_cms_ContentItems.IsContributed=@0", query.IsEssential.Value);
            }

 我定位到该方法,但是不知道 where  not in语句如何写?来个大神

  • zhengw
  • 心远
  • 2014-06-14 21:11 发布

whereSql.Where("spb_cms_ContentItems.ContentFolderId in (@ContentFolderIds)"new { ContentFolderIds = folderIds });

 

这里已经有示例代码了。