Fluent Nhibernate - Mapping child in parent when Child has reference to parent and not using a list
I have a child object in the database that looks like this:
CREATE TABLE Child
(
ChildId uniqueidentifier not null,
ParentId uniqueidentifier not null
)
An then I have a parent like so.
CREATE TABLE Parent
(
ParentId uniqueidentifier not null
)
Now, the problem is that in my Parent class, I have
public virtual Child Child { get; set; }
I don't want to use a list if possible. I know I could use a hasmany to a list and then just select the top 1 from the list in my Parent.Child property.
I've tried references, hasone, referencesany and can't seem to get the mapping right. Anyone have any ideas?
Tha开发者_如何学编程nks,
I model this type of relationship as one-to-many where the many side is restricted to n elements (in this case n=1). I model the many side as a private collection on the parent and restrict the number of elements through the property. See this question.
I had to use a list, and then Child property just grabs the first one in the list. Not idea, but it works.
精彩评论