How to save a child with assigned id in nhibernate

后端 未结 3 1618
面向向阳花
面向向阳花 2020-12-01 10:38

I have two classes:

public class Parent
{
    public virtual long? ID { get; set; } // native
    public virtual IList Children { get; set; }
           


        
3条回答
  •  天涯浪人
    2020-12-01 11:27

    When cascading from a parent to a child, NHibernate uses the SaveOrUpdate method. You are correct that NHibernate need some way to determine whether it should perform an insert or an update. It will look at three different fields for an unsaved value to determine if the entity is new.

    1. Id
    2. Version
    3. Timestamp

    With an assigned Id, you will need either a Version or Timestamp field in order to indicate that the entity is new.

    An alternative would be to call Save() on the children explicitly.

提交回复
热议问题