entity framework entity sql vs linq to entities

后端 未结 2 1642
無奈伤痛
無奈伤痛 2020-12-31 14:44

what\'s the purpose of entity sql, i mean if you have linq to entities why would you need to write queries in string, are there any performance reasons or something ?

2条回答
  •  温柔的废话
    2020-12-31 15:41

    ESQL does allow you to choose a collation on a where clause, something which isn't supported in LINQ-to-Anything. This can be genuinely useful. ESQL also allows you to specify the precise type you want returned when types inherit from each other (as opposed to LINQ's OfType, which returns instances of a certain type and any subtype). Beyond that, I can't think of a great reason to use it. It's occasionally nice to be able to build queries in strings, but DynamicQuery/Dynamic LINQ is generally good enough in the very rare cases where this is necessary.

    I think (perhaps cynically) that the "real" purpose of ESQL is "it predates LINQ."

    Regarding Godeke's point of fixing non-optimal queries, I have yet to see one I couldn't fix by changing the LINQ expression. Both ESQL and L2E end up as CCTs, so the SQL generation pipeline is the same.

提交回复
热议问题