NHibernate still issues update after insert

后端 未结 5 1402
抹茶落季
抹茶落季 2020-12-31 11:13

I have a very simple unidirectional mappings. see below:

    public ContactMap()
    {
        Id(x => x.Id).GeneratedBy.Assigned();
        Map(x => x         


        
5条回答
  •  伪装坚强ぢ
    2020-12-31 11:33

    Try setting inverse to true on the mapping and assigning the relationship in code.

    Inverse means that the child is responsible for holding the ID of the parent.

    e.g.

    var contact = new Contact();
    var phoneNumber = new PhoneNumber();
    phoneNumber.Contact = contact;
    

    That way, when you do the insert for the PhoneNumber record, NH can insert the ContactId without having to do a separate update.

    That's what I used to do in NH 2, I would assume the behaviour still works the same in 3.

提交回复
热议问题