Nuno Filipe Godinho

Tudo sobre .NET e Arquitectura

Recent Posts

Tags

News

Community

Email Notifications

Archives

Melhorias ao Entity Framework 4.0 / Improvements in Entity Framework 4.0 (PT/EN)

(PT)

   Com o .NET 4.0 bastantes novas funcionalidades e tecnologias irão ver a luz do dia, ao mesmo tempo que outras irão ser melhoradas, e a Entity Framework é uma dessas tecnologias que serão melhoradas.

   Muitas destas alterações estão a ser efectuadas ao nível da geração das Queries, o que significa que estão a ser efectuadas ao nível da conversão de Linq para código SQL, e algumas dessas alterações que estão na Beta 1 são as seguintes:

  1. Evitar projectar todas as colunas em queries embutidos
    • Ao invez de efectuar uma query a todas as colunas e depois efectuar a projecção sobre a mesma, simplesmente efectuar imediatamente a projecção e obter apenas as colunas necessárias
  2. Evitar a utilização desnecessária de verificações de IS NULL em queries LINQ to Entities
    • Retirar a utilização de verificações de null em Joins
  3. Outras melhorias nos Joins:  Eliminar a utilização de uma tabela principal em “Left Outer Join”
    • Evitar a necessidade te ter um left outer join para as tabelas principais se as colunas dessas tabelas não são necessárias na projecção
  4. Utilização de IN em vez de OR’s interligados
    • Em vez de utilizar diversos Or’s do género “CategoryId = 1 OR CategoryID = 2 (…)” utilizar “CategoryId In (1,2,…)”
  5. Traduzir mais operadores GroupBy de Linq para SQL GROUP BY
    • Melhor utilização do Group By de SQL de forma a simplificar as queries
  6. Evitar o “Cast (1 as bit)”, utilizar em vez disso o “1”
  7. Simplificar algumas queries através da utilização de subtipos de uma hierarquia

   Algumas das melhorias para depois da Beta 1:

  1. Eliminar os null sentinels
    • Na query gerada muitas vezes existe uma constante 1 que é projectada em ambas as queries. Ao evitar que isto aconteça e ao reutilizaar outras colunas para atingir o mesmo objectivo em muitos casos conseguimos evitar diversos niveis de interligados.
  2. Mais melhorias nos Joins
  3. Utilização dos Inner Joins em vez dos Left Outer Joins sempre que possível
  4. Melhorar o mecanismo de forma a fornecer queries mais eficientes em colunas não Unicode
    • Actualmente são geradas constantes e parâmetros não unicode quando os mesmos são utilizados em queries LINQ to Entities comparativamente com colunas não unicode. Isto permite que possam ser utilizados indices de SQL Server.
  5. Melhorias nas funções de tradução String.StartsWith, String.Contains e String.EndsWith em LINQ to Entites para a utilização do LIKE.
  6. Melhorias na tradução das funções canónicas StartsWith, Contains e EndsWith para utilizar o LIKE (estas funções canónicas estão disponíveis com a versão .NET 4.0 Beta1)
  7. Agrupar diversos cases num único

   Podem ler mais acerca deste tópico neste post da equipa ADO.NET.

(EN)

   With .NET 4.0 a lot of new features and technologies will see the light, as long as others will get improved, and Entity Framework will be one of those technologies that will get improved.

   A lot of this changes are being made on the Query pipeline, that means that are being done on the translation from Linq to SQL code, and some of the changes in Beta 1 are the following:

  1. Avoid projecting all columns in nested queries
    • Instead of making a query for the complete set of columns and the make the projection on top of it, just make the projection and get only the needed columns
  2. Avoiding Unnecessary IS NULL Checks in LINQ to Entities Queries
    • remove the Is null check when using Joins
  3. Additional join elimination:  Eliminate parent table in “Child Left Outer Join Parent”
    • Avoid having a child left outer join if no column from that relation is needed for the projection
  4. Using IN instead of nested OR’s
    • Instead of having several Or’s in place such as “CategoryId = 1 OR CategoryID = 2 (…)” have “CategoryId In (1,2,…)”
  5. Translating more of LINQ’s GroupBy operator into GROUP BY
    • Better use of the SQL Group By in order to simplify the query
  6. Avoiding “Cast (1 as bit)”, using “1” instead
  7. Simplifying some queries that go against a subtype in a type hierarchy

   Some of the changes after Beta 1:

  1. Elimination of null sentinels
    • In the output query there is often the constant 1 projected both in nested and in top-most queries. By avoiding it and reusing other columns for the same purpose in many cases we are able to avoid levels of nesting.
  2. Additional Join Elimination
  3. Use of Inner Joins instead of Left Outer Joins when possible
  4. Provide mechanism for efficient queries on non-Unicode columns
    • We now generate non-unicode constants and parameters when these are used in LINQ to Entities queries in comparisons with non-unicode columns. This allows indexes to be used by SQL Server.
  5. Improve the translation of the functions String.StartsWith, String.Contains and String.EndsWith in LINQ to Entites to use LIKE.
  6. Improve the translation of the canonical functions StartsWith, Contains and EndsWith to use LIKE (these canonical functions became available in .NET 4.0 Beta1)
  7. Collapse multiple Case statements into one

   You can read more about this topic on this ADO.NET Team post.

Leave a Comment

(requerido) 

(requerido) 

(opcional)

 

(requerido) 

If you can't read this number refresh your screen
Enter the numbers above: