FluentNHibernate HasManyToMany 语法
我在找出与 FluentNHibernate 映射多对多关系的正确语法时遇到了一些麻烦。我已经查看了 SO 和其他地方的其他几个问题,但没有看到任何具有相同表结构的内容。希望比我更了解 FNH 的人可以帮助我解决这个问题。这是我的表结构:
CREATE TABLE [dbo].[WorkItems](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[CategoryId] [bigint] NOT NULL,
[DateTime] [datetime] NOT NULL,
[Details] [nvarchar](2000) NULL,
[Duration] [int] NOT NULL,
[DurationInterval] [nvarchar](10) NOT NULL,
[Summary] [nvarchar](150) NOT NULL,
[UserId] [bigint] NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
CREATE TABLE [dbo].[Tags](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
CREATE TABLE [dbo].[TagWorkItems](
[TagId] [bigint] NOT NULL,
[WorkItemId] [bigint] NOT NULL,
CONSTRAINT [TagId_WorkItemId_PK] PRIMARY KEY CLUSTERED
(
[TagId] ASC,
[WorkItemId] ASC
)
TagWorkItems 表中的 TagId 和 WorkItemId 都是返回父表的外键。对于 M2M 关系来说,这是一个非常简单的连接表设置。我的 Tag 类有一个 ICollection 类型的属性,我的 WorkItem 类有一个 ICollection 类型的属性。我似乎无法弄清楚如何为这些属性设置映射。任何建议将不胜感激。谢谢。
I'm having some trouble figuring out the correct syntax for mapping a many-to-many relationship with FluentNHibernate. I've looked at several of the other questions here on SO and other places, but haven't seen anything with, specifically, the same table structure. Hoping someone that knows more than I do about FNH can help me figure this out. Here's my table structures:
CREATE TABLE [dbo].[WorkItems](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[CategoryId] [bigint] NOT NULL,
[DateTime] [datetime] NOT NULL,
[Details] [nvarchar](2000) NULL,
[Duration] [int] NOT NULL,
[DurationInterval] [nvarchar](10) NOT NULL,
[Summary] [nvarchar](150) NOT NULL,
[UserId] [bigint] NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
CREATE TABLE [dbo].[Tags](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
CREATE TABLE [dbo].[TagWorkItems](
[TagId] [bigint] NOT NULL,
[WorkItemId] [bigint] NOT NULL,
CONSTRAINT [TagId_WorkItemId_PK] PRIMARY KEY CLUSTERED
(
[TagId] ASC,
[WorkItemId] ASC
)
TagId and WorkItemId in the TagWorkItems table are both foreign keys back to the parent tables. It's a pretty straight-forward join table setup for a m2m relationship. My Tag class has a property of type ICollection, and my WorkItem class has a property of ICollection. I can't seem to figure out how to setup the Mappings for those properties. Any advice would be greatly appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是 WorkItem 映射可能表示的内容的示例;只读位取决于您将如何维护关系:
Here's an example of what a WorkItem mapping might say; the readonly bit depends on how you're going to maintain the relationship: