流畅的 NHibernate 的亲子关系?

发布于 2024-10-09 02:29:41 字数 1131 浏览 3 评论 0原文

我想为给定的父级创建一个包含 N 个子级的级联树/列表,其中子级也可以成为父级。

给定以下数据结构:

CountryType=1;颜色类型=3;状态类型=5
6,7,8 = {加拿大、美国、墨西哥}
10, 11, 12 = {红、白、蓝}
20,21,22= {加利福尼亚州、佛罗里达州、艾伯塔省}

TreeID  ListTypeID  ParentTreeID           ListItemID   
1            1       Null                   6   (Canada is a Country)
2            1       Null                   7   (US is a Country)
3            1       Null                   8   (Mexico is a Country)
4            3       3                      10  (Mexico has Red)
5            3       3                      11  (Mexico has White)
6            5       1                      22  (Alberta is in Canada)
7            5       7                      20  (California is in US)
8            5       7                      21  (Florida is in US)
9            3       6                     10  (Alberta is Red)
10           3       6                    12  (Alberta is Blue)
11          3       2                      10  (US is Red)
12          3       2                      11  (Us is Blue)

这将如何在 Fluent NHibernate 类中表示?

一些方向将不胜感激。

谢谢。

I would like to create a cascading tree/list of N number of children for a given parent, where a child can also become a parent.

Given the following data structure:

CountryType=1; ColorType=3; StateType=5
6,7,8 = {Can, US, Mex}
10, 11, 12 = {Red, White, Blue}
20,21,22= {California, Florida, Alberta}

TreeID  ListTypeID  ParentTreeID           ListItemID   
1            1       Null                   6   (Canada is a Country)
2            1       Null                   7   (US is a Country)
3            1       Null                   8   (Mexico is a Country)
4            3       3                      10  (Mexico has Red)
5            3       3                      11  (Mexico has White)
6            5       1                      22  (Alberta is in Canada)
7            5       7                      20  (California is in US)
8            5       7                      21  (Florida is in US)
9            3       6                     10  (Alberta is Red)
10           3       6                    12  (Alberta is Blue)
11          3       2                      10  (US is Red)
12          3       2                      11  (Us is Blue)

How would this be represented in Fluent NHibernate classes?

Some direction would be appreciated.

Thanks.

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

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

发布评论

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

评论(2

荆棘i 2024-10-16 02:29:41

如果这个模型没有变得比这更复杂,我会选择一个简单的 TreeNode 实体,它具有 NodeType 枚举属性、Name 属性和 TreeNode 类型的 ParentNode 属性。

如果您计划确实为不同的节点类型添加更多的复杂性,我会选择通过 NodeType 鉴别器子类化为不同节点类型的 TreeNode 实体。

If this model doesn't get any complicated than this I would go for a simple TreeNode entity with a NodeType enum property, a Name property and a ParentNode property of type TreeNode.

If you plan do add some more complexity to the different node types I would go for a TreeNode entity subclassed to different node types by a NodeType discriminator.

四叶草在未来唯美盛开 2024-10-16 02:29:41

树解决方案很好,但在这种情况下,分离型数据模型效果最好。

例如,我有一个给定的列表。然后我想将该列表中的每个项目与多个项目相关联 - 这甚至可能是另一个列表。

因此,我创建了一种名为 LinkedListItems 的类型 - 它们本质上是项目,只是它们包含一条附加信息 - ParentID 字段。

这比树类型的数据模型效果更好,因为我现在可以将辅助列表项与多个主列表项相关联,而树模型将表示 1..* 关系。

Tree solution is good, however in this case, a detached-type data model will work best.

For example, I have a given list. I then want to associate each item of that list with multiple items - which could even be another list.

Thus, I a type called LinkedListItems - which are essentially items, only that they contain one additional piece of information - a ParentID field.

This works better than a tree type of data model because I can now associate a secondary list item with multiple primary list items, whereas a tree model would represent a 1..* relationship.

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