Linq to Entities vs. ESQL Performance

entity-framework entity-sql linq-to-entities

Question

Does ESQL perform faster than Linq to Entities while utilizing the Entity Framework?

I prefer Linq to Entities over ESQL (mostly for the strong-type checking), although some of my team members argue that ESQL performs better. I'd want to fully understand the advantages and disadvantages of each approach.

1
18
5/26/2017 6:48:59 PM

Accepted Answer

The most notable distinctions are:

Strongly typed programming with beautiful query comprehension syntax is called Linq to Entities. Because the "oefrom" occurs before the "choose," IntelliSense can assist you.

Traditional string-based queries are used by entity SQL, which has a more recognizable SQL-like syntax where the SELECT statement occurs before the FROM. Because eSQL is based on strings, dynamic queries may be created at runtime using string manipulation in a conventional manner.

The major distinction that is less visible is:

With the "oeselect new... " syntax of Linq to Entities, you may "project" the results of your query into whatever form you like. This has been made possible by anonymous types, introduced in C# 3.0.

Entity SQL does not support projection since you must always return an ObjectQueryT>. It is feasible to utilize ObjectQueryobject> in certain circumstances, but you must find a solution to the problem. Select consistently yields ObjectQueryDbDataRecord>. see the code below

ObjectQuery<DbDataRecord> query = DynamicQuery(context,
        "Products",
        "it.ProductName = 'Chai'",
        "it.ProductName, it.QuantityPerUnit");

public static ObjectQuery<DbDataRecord> DynamicQuery(MyContext context, string root, string selection, string projection)
{
    ObjectQuery<object> rootQuery = context.CreateQuery<object>(root);
    ObjectQuery<object> filteredQuery = rootQuery.Where(selection);
    ObjectQuery<DbDataRecord> result = filteredQuery.Select(projection);
    return result;
}

There are other more subtle differences described by one of the team members in detail here and here.

17
12/10/2008 3:55:48 PM

Popular Answer

Additionally, some really vile SQL may be produced via ESQL. When I had to dig out an issue with a query that used inherited classes, I discovered that my piddly-little ESQL, which only had four lines, had been converted into a monster SQL statement with 100,000 characters.

I did the same thing with Linq, and the produced code—say let's 20 lines of SQL—was considerably easier to manage.

In addition, Linq is tightly typed, albeit it may be difficult to debug without the edit and continue capability.

AD



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow