2011-12-15 96 views
1

如何在此處轉換日期時間。從數據庫(RDATE)未來的日期時間是JSON格式「/日期(1323975591369)/」,我現在雖然沒有符合條件的記錄與DateTime.Today查詢當前日期的條件查詢中的Json日期格式

比較
int count = session.Query<Movies>("Movie/CurrentList") 
        .Where(x => x.RDate== DateTime.Today) 
        .Count(); 

,我在計數中顯示零結果。

回答

1

ZVenue,您可能只想查詢您的RDate屬性的Date組件。如果是這種情況,只需正確地擴展您的查詢。

但是,我不確定你是否掌握了基本知識,因此我已經組建了一個小型示例應用程序。實際上很無聊,但我希望它有幫助:

class Movie 
{ 
    public string Id { get; set; } 
    public string Name { get; set; } 
    public DateTime Date { get; set; } 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     using (var documentStore = new DocumentStore { Url = "http://localhost:8080/" }) 
     { 
      documentStore.Initialize(); 

      //SeedData(documentStore); 

      using (var documentSession = documentStore.OpenSession()) 
      { 
       var movies = documentSession.Query<Movie>() 
        .Where(x => x.Date.Date == new DateTime(2011, 6, 2)) 
        .ToList(); 

       foreach (var movie in movies) 
       { 
        Console.WriteLine(string.Format("Name: {0}", movie.Name)); 
       } 
      } 
     } 

     Console.Read(); 
    } 

    private static void SeedData(IDocumentStore documentStore) 
    { 
     var movies = new Movie[] 
         { 
          new Movie {Name = "May", Date = new DateTime(2011, 5, 1)}, 
          new Movie {Name = "June", Date = new DateTime(2011, 6, 1)}, 
          new Movie {Name = "June2a", Date = new DateTime(2011, 6, 2)}, 
          new Movie {Name = "June2b", Date = new DateTime(2011, 6, 2)}, 
          new Movie {Name = "June2c", Date = new DateTime(2011, 6, 2, 5, 0, 0)}, 
          new Movie {Name = "June2d", Date = new DateTime(2011, 6, 2, 6, 0, 0)}, 
          new Movie {Name = "June3", Date = new DateTime(2011, 6, 3)}, 
          new Movie {Name = "July", Date = new DateTime(2011, 7, 1)}, 
         }; 

     using (var documentSession = documentStore.OpenSession()) 
     { 
      foreach (var movie in movies) 
      { 
       documentSession.Store(movie); 
      } 

      documentSession.SaveChanges(); 
     } 
    } 
}