Fluent NHibernate one to many uni-directional mapping

落爺英雄遲暮 提交于 2019-12-03 01:59:10

NHibernate doesn't support this mapping when you have a not-null constraint on your foreign key. If you remove that constraint, you'll see that NHibernate inserts the Comments with a null PostId, then updates them with the Id of the new Post.

You either need to:

  1. Remove the not-null constraint and the Inverse call
  2. Keep the constraint, and map the other side of the relationship (making this a bi-directional relationship, and allowing Inverse to work correctly)

This is covered in the NHibernate documentation for one-to-many's, see the Very Important Note at the end.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!