简体   繁体   English

在什么情况下我应该使用Entity SQL?

[英]In what situations should I use Entity SQL?

I was wondering whether there are situation that's more advisable to use ESQL? 我想知道是否有更适合使用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. 通常,我发现ESQL令人沮丧(特别是在需要完全限定实体类型的所有特殊情况下)并且可能使用ESQL完成的任何操作都可以通过SQL或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.) 但我想知道ESQL更适合解决方案的情况,或者比使用SQL或LINQ(更容易/更快地编码或更好的性能等)具有竞争优势的情况

So, what's the compromise here? 那么,这里的妥协是什么? When is it better to use each one of the three approaches in querying over EF4? 什么时候使用三种方法中的每一种来查询EF4更好?

I find that ESQL to be good for edge cases, for example: 我发现ESQL适用于边缘情况,例如:

  1. Where it's just really hard to express something in LINQ. 在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. 此外,如果您了解Entity SQL,您将能够表达QueryViews和模型定义的查询。

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): 我遇到了这些非常相似的问题(我在早些时候输入我的内容时没有显示)堆栈溢出流程,我猜他们有更深入的讨论(尽管T-SQL没有提到很多,但它有点非常明显) :

Note that the two questions are a bit "old" so you might validate some of data based on your current understanding of EF4 请注意,这两个问题有点“旧”,因此您可能会根据您当前对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. 编写模型定义的函数需要Esql,反过来可以通过LINQ to Entities Queries使用。 Most cased you'll be using LINQ to Entities. 大多数人都会使用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. 另一种情况是,当您想要使用存储函数(buit in或UDF)构建查询时,您无法使用LINQ TO Entities us。 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. 在这种情况下,esql是您在EF1中的唯一方法,但在EF4中,您可以使用其功能来公开要在LINQ中使用的那些函数。 About performance, esql is performing better. 关于性能,esql表现更好。 but you might prefer productivity using Linq over performance gain using esql. 但是你可能更喜欢使用Linq而不是使用esql来提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM