开发者

In what situations should I use Entity SQL?

开发者 https://www.devze.com 2023-01-28 04:08 出处:网络
I was wondering whether there are situation that\'s more advisable to use ESQL? Generally, I find ESQL frustrating (specially with all the special cases where you need to fully qualify an entity type

I was wondering whether there are situation that's more advisable to use ESQL?

Generally, I find ESQL frustrating (specially with all the special cases where you need to fully qualify an entity type) & probably anything done using ESQL can be done through SQL or LINQ.

But I was wondering of situations where ESQL is a better fit for a solution or would have a competitive edge over using SQL or LINQ (either easier/faster to code, or better 开发者_运维问答performance, etc.)

So, what's the compromise here? When is it better to use each one of the three approaches in querying over EF4?


I find that ESQL to be good for edge cases, for example:

  1. Where it's just really hard to express something in LINQ.
  2. For building very dynamic searches.
  3. If you want to use a database specific function that is exposed by the provider you are using.

Also, if you know Entity SQL, you will be able to express QueryViews and Model-Defined Queries.


I came across these pretty similar questions (which didn't show up when I typed mine, earlier) on stack over flow, I guess they have deeper discussions (though T-SQL is not mentioned a lot, but it's kinda pretty obvious though):

  • Linq to Entities vs ESQL - Stack Overflow
  • Entity framework entity sql vs linq to entities

Note that the two questions are a bit "old" so you might validate some of data based on your current understanding of EF4


Just as what julie mentioned. Esql is required to write model defined functions which in return can be used through LINQ to Entities Queries. Most cased you'll be using LINQ to Entities. One another case where you can't use LINQ TO Entities us when you want to build queries with store functions, either buit in or UDF. In this case esql is your only way in EF1 but in EF4 you can use its features to expose those functions to be used in LINQ. About performance, esql is performing better. but you might prefer productivity using Linq over performance gain using esql.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号