6

I made a view out of joined tables, and I wanted its 2nd level query cache to be invalidated when the view's base table(s) are updated(within ORM context). The view is mapped like a table on NHibernate

Is this possible on NHibernate? How this is done on xml mapping? Fluent mapping will do too

4

1 回答 1

6

Believe or not, even this is possible with NHibernate. If you'd have for example class mapped like this:

<class name="Contact" table="[dbo].[Contact]" lazy="true" >
    <cache usage="read-write" region="ShortTerm"/>

And there is a view on top of the table [dbo].[Contact] which is mapped to another class:

<class name="ViewContact" table="[dbo].[ViewContact]" lazy="true" >
    <cache usage="read-write" region="ShortTerm"/>
    <!-- at this moment the View and table are treated differently -->

Then the magic setting goes directly under the <cache> and and is called <synchronize>

<class name="ViewContact" table="[dbo].[ViewContact]" lazy="true" >
    <cache usage="read-write" region="ShortTerm"/>
    <synchronize table="[dbo].[Contact]"/>
    <!-- now both caches are synchornized -->

And now, any changes to mapped class Contact will also trigger the cache cleaning of the ViewContact class mapped to the view

于 2013-06-18T17:26:22.790 回答