FluentNHibernate 复合外键的映射
我有一个现有的数据库模式,并希望用 Fluent.NHibernate 替换自定义数据访问代码。数据库架构无法更改,因为它已存在于发货产品中。如果领域对象没有改变或只改变了最小限度,那就更好了。
我在映射一个不寻常的架构构造时遇到问题,该架构用以下表结构说明:
CREATE TABLE [Container] (
[ContainerId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Container] PRIMARY KEY (
[ContainerId] ASC
)
)
CREATE TABLE [Item] (
[ItemId] [uniqueidentifier] NOT NULL,
[ContainerId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Item] PRIMARY KEY (
[ContainerId] ASC,
[ItemId] ASC
)
)
CREATE TABLE [Property] (
[ContainerId] [uniqueidentifier] NOT NULL,
[PropertyId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Property] PRIMARY KEY (
[ContainerId] ASC,
[PropertyId] ASC
)
)
CREATE TABLE [Item_Property] (
[ContainerId] [uniqueidentifier] NOT NULL,
[ItemId] [uniqueidentifier] NOT NULL,
[PropertyId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Item_Property] PRIMARY KEY (
[ContainerId] ASC,
[ItemId] ASC,
[PropertyId] ASC
)
)
CREATE TABLE [Container_Property] (
[ContainerId] [uniqueidentifier] NOT NULL,
[PropertyId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Container_Property] PRIMARY KEY (
[ContainerId] ASC,
[PropertyId] ASC
)
)
现有的域模型具有以下类结构:
alt text http://yuml.me/4e2bcb95
Property 类包含表示属性名称和值的其他成员。 ContainerProperty 和 ItemProperty 类没有其他成员。它们的存在只是为了识别财产的所有者。 Container 和 Item 类具有分别返回 ContainerProperty 和 ItemProperty 集合的方法。此外,Container 类有一个方法,该方法返回对象图中所有 Property 对象的集合。我最好的猜测是,这要么是一种便捷方法,要么是从未删除的遗留方法。
业务逻辑主要与 Item(作为聚合根)一起工作,并且仅在添加或删除 Item 时与 Container 一起工作。
我已经尝试了多种技术来绘制此图,但没有任何效果,因此除非有人要求,否则我不会将它们包含在这里。你会如何映射这个?
I have an existing database schema and wish to replace the custom data access code with Fluent.NHibernate. The database schema cannot be changed since it already exists in a shipping product. And it is preferable if the domain objects did not change or only changed minimally.
I am having trouble mapping one unusual schema construct illustrated with the following table structure:
CREATE TABLE [Container] (
[ContainerId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Container] PRIMARY KEY (
[ContainerId] ASC
)
)
CREATE TABLE [Item] (
[ItemId] [uniqueidentifier] NOT NULL,
[ContainerId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Item] PRIMARY KEY (
[ContainerId] ASC,
[ItemId] ASC
)
)
CREATE TABLE [Property] (
[ContainerId] [uniqueidentifier] NOT NULL,
[PropertyId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Property] PRIMARY KEY (
[ContainerId] ASC,
[PropertyId] ASC
)
)
CREATE TABLE [Item_Property] (
[ContainerId] [uniqueidentifier] NOT NULL,
[ItemId] [uniqueidentifier] NOT NULL,
[PropertyId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Item_Property] PRIMARY KEY (
[ContainerId] ASC,
[ItemId] ASC,
[PropertyId] ASC
)
)
CREATE TABLE [Container_Property] (
[ContainerId] [uniqueidentifier] NOT NULL,
[PropertyId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_Container_Property] PRIMARY KEY (
[ContainerId] ASC,
[PropertyId] ASC
)
)
The existing domain model has the following class structure:
alt text http://yuml.me/4e2bcb95
The Property class contains other members representing the property's name and value. The ContainerProperty and ItemProperty classes have no additional members. They exist only to identify the owner of the Property. The Container and Item classes have methods that return collections of ContainerProperty and ItemProperty respectively. Additionally, the Container class has a method that returns a collection of all of the Property objects in the object graph. My best guess is that this was either a convenience method or a legacy method that was never removed.
The business logic mainly works with Item (as the aggregate root) and only works with a Container when adding or removing Items.
I have tried several techniques for mapping this but none work so I won't include them here unless someone asks for them. How would you map this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
映射应如下所示:
注意:
-
Mapping should look this way:
Note:
-