开发者

Mapping 1 to 0..1 in Fluent NHibernate

Lets say i have two entities;

QuestionAnswer(Id, AnswerValue)
Note(Id, QuestionAnswer_Id,开发者_开发问答 NoteValue)

How would I map this in Fluent Nhibernate? I know that there is a HasOne mapping but this is for a 1 to 1 unless im mistaken?

I could also map it as a 1 to M but would require a List<Note> as a navigation property on my QuestionAnswer entity which again doesnt make much sence for a 1 or 0 to me.

Thanks, Kohan


I've struggled with this also. What I ended up doing is mapping a private collection and using public properties to control the number of elements in the collection. Basically I treat it as a 1..n collection instead of a 1..* collection where n = 1.


Use one-to-one association, and set the Note to null if it is not available.

Also, see Hibernate one to zero or one mapping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜