简体   繁体   中英

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?

Thanks,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM