NHIbernate:将实体中的多行映射到单个对象表示

发布于 2024-10-08 17:39:21 字数 904 浏览 0 评论 0原文

假设我有以下架构:

表:显示 显示 ID 电影ID 剧院_id 显示日期 show_time

表:电影 电影ID 标题 ...

表:剧院 剧院_id 姓名 ...

是否可以创建一个 NHibernate 映射来生成以下对象层次结构?

剧院 - 电影 -- 放映列表,其中每个放映包含 - 日期 -- 时间(以逗号分隔的日期时间字符串)

一些示例数据:

showing_id  movie_id    theater_id  show_date   show_time
-------------------------------------------------------------------------
1       1       1       2010-12-23  13:25
2       1       1       2010-12-23  15:25
3       1       1       2010-12-23  17:25
4       1       1       2010-12-23  19:25
5       1       1       2010-12-24  12:00
6       1       1       2010-12-24  14:45

对于电影 ID 1,我希望将其映射到显示对象列表,其中包含: 显示 1:日期 = 2010-12-23,放映时间:13:25、15:25、17:25、19:25 显示 2:日期 = 2010-12-24,放映时间:12:00、14:45

我假设我需要使用标准 NHibernate 映射约定设置映射,然后将原始数据调整到我正在查找的结构中为了。我想我应该仔细检查一下,确保没有遗漏什么。

谢谢!

Suppose I have the following schema:

Table: Showing
showing_id
movie_id
theater_id
show_date
show_time

Table: Movie
movie_id
title
...

Table: Theater
theater_id
name
...

Is it possible to create a NHibernate mapping that would result in the following object hierarchy?

Theater
- Movie
-- List of Showings where each showing consists of
-- Date
-- Times (comma delimited string of times for the date)

Some sample data:

showing_id  movie_id    theater_id  show_date   show_time
-------------------------------------------------------------------------
1       1       1       2010-12-23  13:25
2       1       1       2010-12-23  15:25
3       1       1       2010-12-23  17:25
4       1       1       2010-12-23  19:25
5       1       1       2010-12-24  12:00
6       1       1       2010-12-24  14:45

For movie ID 1, I'd like this to map to a list of showing objects consisting of:
Showing 1: Date = 2010-12-23, Showtimes: 13:25, 15:25, 17:25, 19:25
Showing 2: Date = 2010-12-24, Showtimes: 12:00, 14:45

I'm assuming that I need to set the mappings using the standard NHibernate mapping conventions and then massage the raw data into the structure I'm looking for. I figured I'd double check and make sure there wasn't something I was missing out on.

Thanks!

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

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

发布评论

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

评论(1

゛时过境迁 2024-10-15 17:39:21

有点像。我会用额外的数据(显示)来建立多对多的关系模型。这被建模为两个一对多关系。这些课程将是:

Theater { TheaterId, Name, ..., IList<Showing> Showings }
Showing { ShowingId, Time, ..., Theater, Movie }
Movie { MovieId, Title, ..., IList<Showing> }

Sort of. I would model this a many-to-many relationship with extra data (the showing). This is modeled as two one-to-many relationships. The classes would be:

Theater { TheaterId, Name, ..., IList<Showing> Showings }
Showing { ShowingId, Time, ..., Theater, Movie }
Movie { MovieId, Title, ..., IList<Showing> }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文