在 Raven DB 中查询 Json 文档 - 传递到 MVC 视图

发布于 2024-11-25 14:23:58 字数 458 浏览 1 评论 0原文

下面是 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"    
   }
}

Below is a Json Document in Raven DB. How can I write a query that gets all movies playing in this theater and pass it on as a model to a view in MVC? Thanks for your help.

 {
  "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"    
   }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

私藏温柔 2024-12-02 14:23:58

实际的查询应该非常简单......
假设你有一个像这样的模型:

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; }
    }
}

...那么 raven 查询可能看起来像这样:

    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 应用程序的一个非常好的示例。

The actual query should be quite simple...
Assuming you have a model like this:

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; }
    }
}

... then the raven query could look like that:

    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);
    }

BUT - I'm wondering why you have your id-property named "TheaterId" instead of "Id", which is the default RavenDB-convention.

Probably you want to look at RacconBlog for a really good example of a well designed MVC-app with RavenDB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文