如何映射关联表中的某些属性

时间:2012-05-09 12:48:56

标签: c# .net nhibernate fluent-nhibernate fluent-nhibernate-mapping

我有以下表格:

CREATE TABLE [dbo].[FirstChild](
    [Id] [bigint] IDENTITY(1,1) NOT NULL,
    [ExternalId] [bigint] NOT NULL,
    [Version] [int] NOT NULL,
    [Title] [nvarchar](250) NOT NULL,
    [Description] [ntext] NULL,
    [Factor1] [decimal](18, 0) NULL,
 CONSTRAINT [PK_FirstChild] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[ParentFirstChilds](
    [ParentId] [bigint] NOT NULL,
    [FirstChildId] [bigint] NOT NULL,
 CONSTRAINT [PK_ParentFirstChilds] PRIMARY KEY CLUSTERED 
(
    [ParentId] ASC,
    [FirstChildId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Parents](
    [Id] [bigint] IDENTITY(1,1) NOT NULL,
    [Title] [nvarchar](250) NOT NULL,
    [Description] [ntext] NULL,
 CONSTRAINT [PK_Parents] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[ParentSecondChild](
    [ParentId] [bigint] NOT NULL,
    [SecondChildId] [bigint] NOT NULL,
 CONSTRAINT [PK_ParentSecondChild] PRIMARY KEY CLUSTERED 
(
    [ParentId] ASC,
    [SecondChildId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[SecondChild](
    [Id] [bigint] NOT NULL,
    [ExternalId] [bigint] NOT NULL,
    [Version] [int] NOT NULL,
    [Title] [nvarchar](250) NOT NULL,
    [Description] [ntext] NULL,
    [SomeProperty1] [nchar](10) NOT NULL,
    [SomeProperty2] [nchar](10) NULL,
    [SomeProperty3] [nchar](10) NULL,
 CONSTRAINT [PK_SecondChild] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[ParentFirstChilds]  WITH CHECK ADD  CONSTRAINT [FK_ParentFirstChilds_FirstChild] FOREIGN KEY([FirstChildId])
REFERENCES [dbo].[FirstChild] ([Id])
GO
ALTER TABLE [dbo].[ParentFirstChilds] CHECK CONSTRAINT [FK_ParentFirstChilds_FirstChild]
GO
ALTER TABLE [dbo].[ParentFirstChilds]  WITH CHECK ADD  CONSTRAINT [FK_ParentFirstChilds_Parents] FOREIGN KEY([ParentId])
REFERENCES [dbo].[Parents] ([Id])
GO
ALTER TABLE [dbo].[ParentFirstChilds] CHECK CONSTRAINT [FK_ParentFirstChilds_Parents]
GO
ALTER TABLE [dbo].[ParentSecondChild]  WITH CHECK ADD  CONSTRAINT [FK_ParentSecondChild_Parents] FOREIGN KEY([ParentId])
REFERENCES [dbo].[Parents] ([Id])
GO
ALTER TABLE [dbo].[ParentSecondChild] CHECK CONSTRAINT [FK_ParentSecondChild_Parents]
GO
ALTER TABLE [dbo].[ParentSecondChild]  WITH CHECK ADD  CONSTRAINT [FK_ParentSecondChild_SecondChild] FOREIGN KEY([SecondChildId])
REFERENCES [dbo].[SecondChild] ([Id])
GO
ALTER TABLE [dbo].[ParentSecondChild] CHECK CONSTRAINT [FK_ParentSecondChild_SecondChild]
GO

tables

如何使用FluentNHibernate映射以下类:

public class BusinessKey
{
   public virtual long ExternalId { get;set;}
   public virtual int Version { get; set; }
}

public class Parent
{
     public virtual long Id { get; set; }
     public virtual string Title { get; set; }
     public virtual string Description { get; set; }


     public virtual IList<BusinessKey> FirstChilds { get; set; }
     public virtual IList<BusinessKey> SecondChilds { get; set; }
}

我在映射FirstChilds和SecondChilds时遇到问题。没有找到任何解决方案如何映射它们。

0 个答案:

没有答案