2012-11-02 137 views
1

我需要這樣做:Linq和Datetime一起工作?

context.Ads.Where(c => c.PublishedDate.HasValue && 
     c.EndDate.HasValue && 
     c.EndDate.Value.AddTicks(c.PublishedDate.Value.Ticks) > currentTime && 
     c.AdStatusMail.Where(b => b.StatusKey != (int)AdStatusMailKey.EndedRemainder && b.StatusKey != (int)AdStatusMailKey.MiddleRemainder).Count() < 1) 
     .ToList(); 

的問題是,AddTicks不容Linq中的使用。我看了EntityFunctions,但看不到如何使用它來做我需要的東西?

+1

LINQ to SQL的實體框架? – jrummell

+0

對,LINQ to _what_? –

回答

1

IQueryable無法處理蜱蟲,使它IEnumerable(或tolist)。這裏是一個例子:

context.Ads.Where(c => c.PublishedDate.HasValue && c.EndDate.HasValue && c.AdStatusMail.Where(b => b.StatusKey != (int)AdStatusMailKey.EndedRemainder && b.StatusKey != (int)AdStatusMailKey.MiddleRemainder).Count() < 1) 
      .AsEnumerable() 
      .Where (c => c.EndDate.Value.AddTicks(c.PublishedDate.Value.Ticks) > currentTime) 
      .ToList();