none
Uso de include en consultas de datos RRS feed

  • Question

  • Hola comunidad!

    Tengo una duda. Estoy trabajando en una app donde aplicamos un patro DDD para el acceso a datos, para esto tenemos un repositorio de acceso a datos generico y un patro de especificaciones.
    mi duda es la siguiente. Puedo optimizar una consulta en la cual use un include. 

    Esta es la consulta del SQlProfile

    exec sp_executesql N'SELECT [m.MasterAreas].[AreaCode], [m.MasterAreas].[ApplicationCode], [m.MasterAreas].[AreaName], [m.MasterAreas].[CreatedBy], [m.MasterAreas].[CreatedDate], [m.MasterAreas].[Icon], [m.MasterAreas].[IsActive], [m.MasterAreas].[IsDeleted], [m.MasterAreas].[ApplicationCode], [m.MasterAreas].[ModifiedBy], [m.MasterAreas].[ModifiedDate], [m.MasterAreas].[ShotName], [m.MasterAreas].[SystemDefault]
    FROM [Master_Area] AS [m.MasterAreas]
    INNER JOIN (
        SELECT [m0].[ApplicationCode]
        FROM [Master_Application] AS [m0]
        WHERE [m0].[ApplicationCode] = @__userCode_0
    ) AS [t] ON [m.MasterAreas].[ApplicationCode] = [t].[ApplicationCode]
    ORDER BY [t].[ApplicationCode]',N'@__userCode_0 nvarchar(20)',@__userCode_0=N'S001'

    Que impacto puede tener este tipo de consultas en una aplicacion de mucho volumen de datos?

    Es optimo que EF me envie este query a SQL?

    • Moved by CoolDadTx Monday, July 22, 2019 1:48 PM Wrong locale
    Friday, July 19, 2019 6:15 PM

Answers

  • [ Responding in English because you asked in the English forum. There is a Spanish forum here: https://social.msdn.microsoft.com/Forums/es-ES/home?forum=vcses ]

    Yes, when you use .Include in linq-to-Entties you can get the type of query that you are seeing. In general, you don´t need to worry: the SQL optimizer will generate a good plan to resolve it. You can verify the plan by copying the query into SSMS and clicking on the "show plan" button. If you see any table scans you can probably optimize it by adding an index, but that would not be the fault of the particular shape of the query; you would have the same problem if you had written a straightforward join.

    • Marked as answer by jose_boliv Thursday, August 8, 2019 4:25 AM
    Friday, July 19, 2019 6:43 PM