I got the following weak entity (can not exist without WikiPage):
CREATE TABLE WikiPageTree
(
PageId int NOT NULL,
Title nvarchar(1000) NOT NULL,
Lineage nvarchar(1000) NOT NULL,
)
Where PageId is a FK to Page.Id. It’s a 1-1 mapping.
How should the mapping look like? I can’t figure out how to specify the Id mapping that fluent-nhibernate requires.
I tried the following as suggested in the answer by @WillDaBest:
public class WikiPageTreeMap : ClassMap<WikiPageTreeNode>
{
public WikiPageTreeMap()
{
Table("WikiPageTree");
LazyLoad();
Id(Reveal.Member<WikiPageTreeNode>("PageId")).GeneratedBy.Foreign("Page");
HasOne(x=>x.Page).Constrained().ForeignKey();
//Id(x => x.Page).Column("PageId");
//References(x => x.Page).Column("PageId");
Map(x => x.Path).Column("Title").Not.Nullable().Length(1000);
Map(x => x.Lineage).Column("Lineage").Not.Nullable().Length(1000);
}
}
But it gives me the error
{“Must declare the scalar variable \”@p0\”.”}
This might help with mapping a one-to-one relationship in Fluent nHibernate: http://brunoreis.com/tech/fluent-nhibernate-hasone-how-implement-one-to-one-relationship/