2011-07-21 34 views
1

以下是Raven DB中的Json文檔。我該如何編寫一個查詢來獲取在這個劇場中播放的所有電影,並將其作爲模型傳遞給MVC中的視圖?謝謝你的幫助。在Raven DB中查詢Json文檔 - 傳遞給MVC視圖

{ 
    "TheaterId": "Hd45", 
    "TheaterName" : "Blvd", 

    { 
    "MovieName": "Wild wild west", 
    "ReleaseDate": "12th Dec", 
    "NumOfShows ": "5"  
    } 
    { 
    "MovieName": "Shrek", 
    "ReleaseDate": "12th Dec", 
    "NumOfShows ": "5"  
    } 
    { 
    "MovieName": "Ronin", 
    "ReleaseDate": "12th Dec", 
    "NumOfShows ": "5"  
    } 
} 
+0

看看[NoSQL with RavenDB and ASP.NET MVC - Part 1](http://weblogs.asp.net/shijuvarghese/archive/2010/05/26/nosql-with-ravendb-and-asp -net-mvc-part-1.aspx)希望這會有所幫助,馬特 –

回答

1

的實際查詢應該是很簡單...... 假設你有一個這樣的模式:

public class Theater 
{ 
    public string TheaterId { get; set; } 
    public string TheaterName { get; set; } 

    public List<Movie> Movies { get; set; } 

    public class Movie 
    { 
     public string MovieName { get; set; } 
     public string ReleaseDate { get; set; } 
     public int NumOfShows { get; set; } 
    } 
} 

...於是烏鴉查詢可以看起來像:

private ActionResult MoviesForTheater(string theaterId) 
    { 
     var theater = Session.Load<Theater>(theaterId); 
     if (theater == null) 
      return HttpNotFound("Theater not found!"); 

     var movies = theater.Movies.Select(movie => movie.MovieName).ToList(); 
     return View(movies); 
    } 

但我想知道爲什麼你有你的id屬性命名爲「TheaterId」而不是「Id」,這是默認的RavenDB約定。

也許你想看看RacconBlog是一個很好的例子,用RavenDB精心設計的MVC應用程序。