NHibernate is much to many inefficiency?

I am trying to set up a sample project using NHibernate and Fluent NHibernate. I am using example mappings from the Fluent NHibernate website.

My question is about many-to-many comparisons between Store and Product. It seems that when adding a product to the repository, NHibernate deletes all the records from the association table (StoreProduct) belonging to that repository, and then reinserts all the records, including the association with the new product that I added.

Is this the default behavior or am I missing something? It doesn't seem to be very efficient to delete and reinsert all associations every time I need to add them.

+3
source share
1 answer

This is the expected behavior. I believe this should only happen when you use the bag matching strategy , which is apparently used in this example. The bag indicates that there is an unordered collection that may have duplicate items. Since the elements of the bag are not unique, NHibernate cannot tell when you easily added or removed an item from the bag. The easiest thing for NHibernate is to remove all associations and then add it again.

, "--" ( "--" ), , , , ( ), , . , , - , .

+5

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


All Articles