-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
one-to-one causing N+1 SQL Select statements #3616
Comments
@rodrigo-web-developer No idea about this one, but a similar issue I am also facing. Can you help me with this issue #3615, and do you have anything about this issue? Please let me know |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see this problems occurs in #2716 #3292 #850.
But I didnt see any solution for the problem.
I'm using NHibernate v5.5.2 and has an one-to-one relation mapped.
I try to add batch-size in every XML mapping file. It seems to work only with many-to-one relations.
I reproduced this problem in the repository: https://github.com/rodrigo-web-developer/many-to-one-problem
Basically, I have a Product which has a Category (many-to-one). Product has a tax configuration (ProductTax, which is one-to-one).
The mapping files looks like:
As you can see I added
lazy="false"
andbatch-size="100"
to all mappings.I made a bunch of query examples. Consider that I have 10 products:
The first one (product only) results in 2 selects, so batch-size solved many-to-one problem.
The second one (producttax) gives the N+1 selects:
The third one, which is one of the suggested in linked issues (using QueryOver makes query create full join select):
The last one, forcing join with LINQ work as well:
I have an IRepository<T>, which is a generic interface with
public IQueryable<T> Query()
method, it calls .Query from ISession. I cant change this code base to use QueryOver because it returns IQueryOver (NHibernate specific interface), not an IQueryable and I dont know the impact of changing ALL ENTITIES to use QueryOver. So I want to use Query() which works fine, but in the case of one-to-one relation it is a problem.There is a solution for one-to-one relation? If not, there is any work around for this kind of problem?
The text was updated successfully, but these errors were encountered: