我正在使用 Fluent NHibernate 在数据库中插入一个父对象,这个对象有一个孩子,这个孩子已经保存在数据库中,但我只有这个孩子的 id。
如何插入带有外键(子)的父对象,仅将 id 设置为子对象?
例子:
ObjectParent parent = new ObjectParent();
ObjectChild child = new ObjectChild();
child.Id = 5; // 5 is the id from the child in the database
parent.Child = child;
Service.Create(parent); // here I need to insert the parent with the referenced foreign key (id = 5)
编辑:
我无法从数据库中获取子对象。