开发者

FluentHibernate: how to specify join-mapped table should never be inserted into

开发者 https://www.devze.com 2023-03-10 21:57 出处:网络
I have the following FluentNHibernate mapping: public AssetMap() { Table(\"PRASSET\"); Id(x => x.Id).Column(\"PRA_RECNUM\").GeneratedBy.Sequence(\"PRA_RECNUM_GEN\");

I have the following FluentNHibernate mapping:

public AssetMap()
    {
      Table("PRASSET");
      Id(x => x.Id).Column("PRA_RECNUM").GeneratedBy.Sequence("PRA_RECNUM_GEN");
      ...fields mapped from PRASSET table
      Join("PRSTOCK", m =>
      {
        m.Fetch.Join();
        m.Optional();
        m.KeyColumn("PRS_ASSRN");
        ...fields mapped from PRSTOCK table
      });
    }

As the m.Optional() call in the Join bit suggests, there may or may not be a corresponding PRSTOCK record.

The problem I am h开发者_JS百科aving is that when I save an Asset instance which is dirty only in respect of one of its PRASSET-mapped properties, and there isn't a corresponding PRSTOCK record, it's inserting one! This is emphatically not what I want to happen, since there should not be a corresponding PRSTOCK record in most cases.

Is there a tweak in the mapping configuration I can try? It would be enough at this stage just to prevent records ever being inserted into PRSTOCK, but ideally NHibernate should not try to update or insert PRSTOCK unless one of the Asset instance's properties mapped to PRSTOCK has been dirtied.


According to this blog post, NHibernate will always try to insert join-mapped records if the properties are not null. So I have made the appropriate properties nullable (default null) and hopefully it won't try to insert anymore.

0

精彩评论

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

关注公众号