-1

While I am working a project I have seen this line of NHibernate mapping

HasMany(entity => entity.Tasks).KeyColumn("APPLICATION_ID").Cascade.AllDeleteOrphan().ReadOnly().Inverse();

it is the first time for me I see some one using the inverse and readonly attributes so please could anyone explain them to me.

Mo Haidar
  • 3,748
  • 6
  • 37
  • 76
  • 2
    https://stackoverflow.com/questions/713637/inverse-attribute-in-nhibernate – David Osborne Jun 14 '17 at 16:03
  • Possible duplicate of [Inverse Attribute in NHibernate](https://stackoverflow.com/questions/713637/inverse-attribute-in-nhibernate) – Frédéric Jun 15 '17 at 13:23
  • The rational behind `inverse` is further documented in [NHibernate reference](http://nhibernate.info/doc/nhibernate-reference/collections.html#collections-bidirectional), it is an essential mechanism for bidirectional associations. And `Readonly` is a shorthand for `mutable="false"`, as explained [here](http://notherdev.blogspot.fr/2012/01/mapping-by-code-set-and-bag.html). See [ask], you are supposed to do some research before asking. – Frédéric Jun 15 '17 at 13:58

1 Answers1

0

You can find a detailed description of inverse here

TLDR; from the link

  • Inverse is a boolean attribute that can be put on the collection mappings, regardless of collection's role (i.e. within one-to-many, many-to-many etc.), and on join mapping.

  • We can't put inverse on other relation types, like many-to-one or one-to-one.

  • By default, inverse is set to false.
  • Inverse makes little sense for unidirectional relationships, it is to be used only for bidirectional ones.
  • General recommendation is to use inverse="true" on exactly one side of each bidirectional relationship.
  • When we don't set inverse, NHProf will complain about superfluous updates.

And this link for Readonly

TLDR;

The only difference apart from different naming for some properties and Property vs. Map name itself is the ReadOnly method available in FNH. It is just a shortcut for setting both .Not.Insert() and .Not.Update().

Fran
  • 6,440
  • 1
  • 23
  • 35
  • There is no `update`or `insert` attributes on collections mapping. For collections, Fluent `ReadOnly` is a shorthand for `mutable="false"`. – Frédéric Jun 15 '17 at 13:54