2010-11-23 117 views
-1
string NewsFillter = string.Empty; 
      List<string> PublishDatePostMeta = (from post in postrepository.GetAllPosts() 
           join pstmt in postrepository.GetAllPostMetas() 
           on post.int_PostId equals pstmt.int_PostId 
           where (post.int_PostTypeId == 4 && post.int_PostStatusId == 2 && post.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId) && pstmt.vcr_MetaKey=="Publish Date" 
           select pstmt.vcr_MetaValue).ToList(); 
      int DatesCount = PublishDatePostMeta.Count();   
      foreach (string PublishDate in PublishDatePostMeta) 
      { 
       if (PublishDate != "") 
       { 
        NewsFillter += System.DateTime.Now + ">=" + Convert.ToDateTime(PublishDate); 
       } 
      }        

      var postsidebar = from post in postrepository.GetAllPosts() 
           join pstmt in postrepository.GetAllPostMetas() 
           on post.int_PostId equals pstmt.int_PostId 
           where (post.int_PostTypeId == 4 && post.int_PostStatusId == 2 && post.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId) 
           && (pstmt.vcr_MetaKey.Contains(filter) && pstmt.vcr_MetaValue.Contains("true")) 
           select post; 

1日问题.The事情是如何NewsFillter将在postsidebar查询后,在真正的(我将将它放在包含数PreparedStatement pstmt对象accomdated,等于加入或什么)。asp.net的MVC LINQ日期时间问题

第二个问题。是否有任何方式,大块(之间& & s)返回枚举,我可以摆脱这一点。在这一刻它不是允许该

回答

1

我没有udnerstood你正确的,但如果你想申请多个过滤器,这里是我的解决方案:

//Book is a table in the database 
List<Expression<Func<Book, bool>>> filters = new List<Expression<Func<Book, bool>>>(); 
IQueryable<Book> query = dc.Books; 

filters.Add(b => b.BookId == long.Parse(id)); 
//apply all filters 
foreach (var f in filters) 
    query = query.Where(f); 

您的问题:

  1. 这个问题需要一个输入和输出的例子。尝试是这样的:

    || pstmt.vcr_MetaKey=="Publish Date" && ( pstmt.vcr_MetaValue == "" || DateTime.Parse(pstmt.vcr_MetaValue) < DateTime.Now)

  2. 有方法AsEnumerable,如果你的意思是我的想法。

+0

你是亲密的,我假设查询将有一个连接的结果基于所有f? – maztt 2010-11-23 11:31:22