我有一对PO:
public abstract class DataObject : IDataObject
{
public virtual Guid ObjectID { get; set; }
public virtual IList<ObjectProperty> Properties { get; set; }
}
public class ObjectProperty : IProperty
{
public virtual Guid ObjectPropertyID { get; set; }
public virtual DataObject Object { get; set; }
public virtual string Name { get; set; }
public virtual string Value { get; set; }
public virtual string Type { get; set; }
public virtual int? Scale { get; set; }
public virtual int? Precision { get; set; }
}
我有这样的地图:
public class DataObjectMapping : ClassMap<DataObject>
{
public DataObjectMapping()
{
Table("DataObjects");
this.MapIDataObjectProperties();
this.MapIHasProperties();
}
}
public ObjectPropertyMapping()
{
Table("ObjectProperties");
Id(x => x.ObjectPropertyID).Column("ObjectPropertyID");
References(x => x.Object).Index("ixObject.Name").Column("ObjectID").Not.Nullable();
Map(x => x.Name).Index("ixObject.Name").Length(100).Not.Nullable();
Map(x => x.Scale);
Map(x => x.Precision);
Map(x => x.Type);
Map(x => x.Value);
}
}
我正在绘制接口特性图,如:
public static void MapIHasProperties<T>(this ClassMap<T> target) where T : IHasProperties
{
target.HasMany(x => x.Properties);
}
当我使用我的数据库(MSSQL 2005年)时,我会利用这一数据库(MSSQL 2005年)制作。
public static ISessionFactory SessionFactory
{
get
{
if (_SessionFactory == null)
{
var config = new Configuration().Configure();
_SessionFactory = Fluently.Configure(config)
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf<Site>()
.Conventions.Add<CustomForeignKeyConvention>())
.ExposeConfiguration(c => { new SchemaExport(c).Create(false, true); })
.BuildSessionFactory();
}
return _SessionFactory;
}
}
I end up with things linking properly, but with an extra column in my ObjectProperties table, and I don t understand why:
USE [Sandbox]
GO
/****** Object: Table [dbo].[ObjectProperties] Script Date: 11/01/2011 13:50:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ObjectProperties](
[ObjectPropertyID] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](100) NOT NULL,
[Scale] [int] NULL,
[Precision] [int] NULL,
[Type] [nvarchar](255) NULL,
[Value] [nvarchar](255) NULL,
[ObjectID] [uniqueidentifier] NOT NULL,
[DataObject_id] [uniqueidentifier] NULL,
PRIMARY KEY CLUSTERED
(
[ObjectPropertyID] 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
ALTER TABLE [dbo].[ObjectProperties] WITH CHECK ADD CONSTRAINT [FKFBE776BE7C346D9] FOREIGN KEY([DataObject_id])
REFERENCES [dbo].[DataObjects] ([ObjectID])
GO
ALTER TABLE [dbo].[ObjectProperties] CHECK CONSTRAINT [FKFBE776BE7C346D9]
GO
ALTER TABLE [dbo].[ObjectProperties] WITH CHECK ADD CONSTRAINT [FKFBE776BF671B18E] FOREIGN KEY([ObjectID])
REFERENCES [dbo].[DataObjects] ([ObjectID])
GO
ALTER TABLE [dbo].[ObjectProperties] CHECK CONSTRAINT [FKFBE776BF671B18E]
Can someone explain to me why I have 2 columns with foreign keys being mapped to the same column in the DataObjects table, and how I can prevent that from happening?