none
Performance when using Include RRS feed

  • Question

  • Hello!

    Will the performance when using .Include also be improved?

    If yes, when is it going to happen?

     

    Best regards,

    Henrik Dahl

     

    Monday, August 15, 2011 3:50 PM

Answers

  • Hi,

    when using Include, there is only one connection made to the data source and a larger amount of data is returned in the initial query.

    when not - you have a less complex query and less result, though each successive call to a related object makes a connection to the data source and executes a query.

    so, performance depends on the scenario, you'd choose between the number of connections made to the data source and the amount of data returned.

     

    Regards


    Clarity VS Precision
    Thursday, August 25, 2011 10:09 AM

All replies

  • Hi Henrik,

    Welcome!

    I think the .Query() method can improve the performance. 

    Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query. Eager loading is achieved by use of the Include method. I don't think it can improve the performance.

    You can refer here.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 16, 2011 8:00 AM
    Moderator
  • Alan,

     

    OK, I'll ask more precisely. Wiil the SQL queries generated for .Include be changed in order to increase efficiency?

    Other people find it also problematic, Try to see the comments section at: http://blogs.msdn.com/b/adonet/archive/2011/07/25/generated-sql-improvements-for-tpt-queries.aspx:

    (start)

    We use the Include method to eagerly load child entities. The issue is that EF still creates a lot of UNIONs and testing the EF-generated query that against a manually (and an equivalent) created query, it falls way far behind in terms of performance. ...

    (finish)

     

    Best regards,

    Henrik Dahl

     

    Tuesday, August 16, 2011 7:23 PM
  • Hi Henrik,

    Thanks for your feedback.

    We will do some more pending research  about your problem and come back as soon as possible, Thanks for understanding.
    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 17, 2011 12:56 PM
    Moderator
  • Alan,

     

    OK, I'll ask more precisely. Wiil the SQL queries generated for .Include be changed in order to increase efficiency?

    Other people find it also problematic, Try to see the comments section at: http://blogs.msdn.com/b/adonet/archive/2011/07/25/generated-sql-improvements-for-tpt-queries.aspx:

    (start)

    We use the Include method to eagerly load child entities. The issue is that EF still creates a lot of UNIONs and testing the EF-generated query that against a manually (and an equivalent) created query, it falls way far behind in terms of performance. ...

    (finish)

     

    Best regards,

    Henrik Dahl

     

    Hi Henrik,

    I go through the blog and see the comments there. This is June 2011 CTP version.

    Several SQL generation improvements, especially around optimizing queries over models with table-per-type (TPT) inheritance. unfortunately, there is not changes for include method. I tested and compared them on EF4.1 and  June CTP, I found the T-SQLs which generated by them are same.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 25, 2011 9:29 AM
    Moderator
  • Hi,

    when using Include, there is only one connection made to the data source and a larger amount of data is returned in the initial query.

    when not - you have a less complex query and less result, though each successive call to a related object makes a connection to the data source and executes a query.

    so, performance depends on the scenario, you'd choose between the number of connections made to the data source and the amount of data returned.

     

    Regards


    Clarity VS Precision
    Thursday, August 25, 2011 10:09 AM