NHibernate Bidirectional Multiuser Relationship Caching Problem

I am having a problem with bidirectional caching of ManyToMany relationships

First Side Display:

        HasManyToMany(x => x.Jobs)
            .Table("ProfileSuggestStoryJob")
            .AsSet()
            .Cascade.None()
            .ParentKeyColumn("ProfileSuggestStoryId")
            .ChildKeyColumn("JobId")
            .Cache.ReadWrite();

Second side display:

        HasManyToMany(x => x.SuggestedProfiles)
            .Table("ProfileSuggestStoryJob")
            .AsSet()
            .Cascade.None()
            .ParentKeyColumn("JobId")
            .ChildKeyColumn("ProfileSuggestStoryId")
            .Inverse().Cache.ReadWrite();

The first side is responsible for inserting / updating / deleting, and is also well kept. But on the other hand, the cache is not updated, and the collection does not contain a newly added entity.

Without a cache, everything works fine ...

+3
source share
1 answer

Each side of the relationship has its own cache; NHibernate will not invalidate the second side cache due to changes in the first side.

You can use SessionFactory.EvictCollectionto cancel it manually.

+3

Source: https://habr.com/ru/post/1749187/


All Articles