locked
Is it dangerous to use Include ThenInclude RRS feed

  • Question

  • User283528319 posted

    Hi all,

    Because of the DB normalization, I use master <g class="gr_ gr_78 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="78" data-gr-id="78">db</g> detail <g class="gr_ gr_94 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="94" data-gr-id="94">db</g> and another detail <g class="gr_ gr_117 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="117" data-gr-id="117">db</g> 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?

    Thursday, February 21, 2019 12:14 PM

All replies

  • User753101303 posted

    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 ?)

    Thursday, February 21, 2019 12:24 PM
  • User1120430333 posted

    You could just use a Linq Join, which is similar to T-SQL Join. 

    Thursday, February 21, 2019 2:05 PM
  • User283528319 posted

    Is there any sample for it?

    And most importantly, is it necessary for some reason?

    Thursday, February 21, 2019 2:18 PM
  • User753101303 posted

    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.

    Thursday, February 21, 2019 3:31 PM
  • User1120430333 posted

    Is there any sample for it?

    And most importantly, is it necessary for some reason?

    Sample for what? Who are you posting the question to?

    Thursday, February 21, 2019 5:10 PM