开发者

Relating classes in NHibernate

I have a situation where I have a class that is referenced by several other classes. For example, my ContactInformation class is referenced by multiple different classes, such as Customer, Business, Location, etc. Since it is referenced by multiple classes, I am unsure of how to make a two-way mapping so I can insert a Customer with its Contact Information. As a result, I am getting an error on insert because ContactInformation is seen as null.

Has anybody ever run into a situation like this? Thanks f开发者_开发百科or any help!


I would map the ContactInformation as a many-to-one with cascade="all". When you create a new Customer you'll need to also create a new ContactInformation (unless it allows nulls). Then when you SaveOrUpdate the Customer it will cascade and SaveOrUpdate the ContactInformation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜