我有两张桌子的基地:
dbo.AEntity& dbo.BEntity
public class AEntity : EntityBase
{
public virtual BEntity BClass { get; set; }
public virtual string SomeAString { get; set; }
}
public class BEntity : EntityBase
{
public virtual string SomeBString { get; set; }
}
这是我的映射:
public class AMap : ClassMap<AEntity>
{
public AMap()
{
Table("AEntity");
Map(x => x.CreateDate);
Map(x => x.UpdateDate);
Map(x => x.Deleted);
Id(x => x.Id).GeneratedBy.GuidComb();
HasOne(x => x.BClass).ForeignKey("BEntity_Id").Fetch.Join().Cascade.All();
}
}
public class BMap : ClassMap<BEntity>
{
public BMap()
{
Table("BEntity");
Map(x => x.CreateDate);
Map(x => x.UpdateDate);
Map(x => x.Deleted);
Id(x => x.Id).GeneratedBy.GuidComb();
}
}
问题是当我保存图表时,BClass_Id为空。
我做错了什么?
CREATE TABLE [dbo].[AEntity] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[SomeAString] NVARCHAR (MAX) NULL,
[CreateDate] DATETIME NOT NULL,
[UpdateDate] DATETIME NULL,
[Deleted] BIT NOT NULL,
[BClass_Id] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_dbo.AEntity] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_dbo.AEntity_dbo.BEntity_BClass_Id] FOREIGN KEY ([BClass_Id]) REFERENCES [dbo].[BEntity] ([Id]));
创建非集群索引[IX_BClass_Id] ON [dbo]。[AEntity]([BClass_Id] ASC);