Yes it can use issues if you chain too many includes as the strategy was to do that using a single query increasing the resultset size with each new include. If I remember EF Core changed that and likely generates multiple SQL queries isntead and process
multiple resulsets (would have to try)...
The basic idea is to make sure you load data you'll really need. Avoid include if you'll end up in using a small portion of what you load (ie do you really show all master and all details on a single page ?)
It could be easier the other way round ie do you have a problem and what is your use case ? The first step would be to make sure that all what you load is really useful which includes :
- not loading too many rows and then just let the user to filter out among them, with a web app you try to let the user filter first before showing anything (or at least a single page of 50 rows for example)
- similarly not loading columns (especially long text or binarty columns) that you won't show right away
For master/detail you usually load master data maybe with a detail summary (a command amount or whatever) and then you show details when the main row is selected, for a treeview you could load data on demand etc...
In short load what is immediately visible. For anything else wonder if it will be liekly seen in most cases (you can then load) or if it's less likely (in which case you'll likely try to load this on demand). It could be also a design issue on the database
side (ie lacking indexes on foreign keys for example).
If you DON'T have a problem right now, keep that in mind but avoid to spend time on this if you don't have an actual issue.
Member
92 Points
534 Posts
Is it dangerous to use Include ThenInclude
Feb 21, 2019 12:14 PM|fatihbarut|LINK
Hi all,
Because of the DB normalization, I use master db detail db and another detail db under the first one.
But this means I need to use Include ThenInclude to call the data.
I just have concerns about the performance of this approach.
Does this join process cause any performance issue?
All-Star
48530 Points
18075 Posts
Re: Is it dangerous to use Include ThenInclude
Feb 21, 2019 12:24 PM|PatriceSc|LINK
Hi,
Yes it can use issues if you chain too many includes as the strategy was to do that using a single query increasing the resultset size with each new include. If I remember EF Core changed that and likely generates multiple SQL queries isntead and process multiple resulsets (would have to try)...
The basic idea is to make sure you load data you'll really need. Avoid include if you'll end up in using a small portion of what you load (ie do you really show all master and all details on a single page ?)
Contributor
4953 Points
4208 Posts
Re: Is it dangerous to use Include ThenInclude
Feb 21, 2019 02:05 PM|DA924|LINK
You could just use a Linq Join, which is similar to T-SQL Join.
Member
92 Points
534 Posts
Re: Is it dangerous to use Include ThenInclude
Feb 21, 2019 02:18 PM|fatihbarut|LINK
Is there any sample for it?
And most importantly, is it necessary for some reason?
All-Star
48530 Points
18075 Posts
Re: Is it dangerous to use Include ThenInclude
Feb 21, 2019 03:31 PM|PatriceSc|LINK
It could be easier the other way round ie do you have a problem and what is your use case ? The first step would be to make sure that all what you load is really useful which includes :
- not loading too many rows and then just let the user to filter out among them, with a web app you try to let the user filter first before showing anything (or at least a single page of 50 rows for example)
- similarly not loading columns (especially long text or binarty columns) that you won't show right away
For master/detail you usually load master data maybe with a detail summary (a command amount or whatever) and then you show details when the main row is selected, for a treeview you could load data on demand etc...
In short load what is immediately visible. For anything else wonder if it will be liekly seen in most cases (you can then load) or if it's less likely (in which case you'll likely try to load this on demand). It could be also a design issue on the database side (ie lacking indexes on foreign keys for example).
If you DON'T have a problem right now, keep that in mind but avoid to spend time on this if you don't have an actual issue.
Contributor
4953 Points
4208 Posts
Re: Is it dangerous to use Include ThenInclude
Feb 21, 2019 05:10 PM|DA924|LINK
Sample for what? Who are you posting the question to?