QueryExpression 与 FetchXml CRM2011
我们发现 Linq for CRM 2011 严重损坏 - 它似乎在没有对其进行任何 QA 的情况下就进入了。指示提供程序损坏程度的指标是像 .Where(x => x== "b") 这样的查询可以工作,但是这个 .Where(x => "b" == x) 可能不依赖于某些前面的条件就像一个 join 语句。实际上,我不得不重写查询提供程序的部分内容,并且我对我整理的垃圾感到幸运。
然而,这种情况不能继续下去,仍然存在其他问题,而且我没有报酬为 MS 工作,所以我正在寻找替代方案。这两个出现了 QueryExpression & FetchXml 详细信息如下: http://msdn.microsoft.com/en-us/ library/gg334607.aspx
谁能给我一个诚实的、现实生活中使用 QueryExpression 与 FetchXml 的优缺点?我想知道它们在性能、开发速度、稳健性和灵活性方面的比较如何。
We found out that Linq for CRM 2011 is horribly broken - it seems to have gotten in without any QA performed on it. An indicator as how badly broken the provider is a query like .Where(x => x== "b") works but this .Where(x => "b" == x) might not depending on some preceding condition like a join statement. I have actually had to rewrite parts of the query provider and am enjoying better luck with the crap I put together.
However this can't go on, there are still other issues and I'm not paid to to work for MS, so I'm looking at alternatives. These 2 came up QueryExpression & FetchXml as detailed here: http://msdn.microsoft.com/en-us/library/gg334607.aspx
Can anyone give me an honest, real life pros and cons of using QueryExpression vs. FetchXml? I would like to know how they compare in terms of performance, development speed, robustness and flexibility.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了以 Anwar 重点关注 LINQ 与 FetchXml 的优秀答案为基础,我将补充一点:我从不使用
QueryExpression
。 为什么?因此,它的查询能力比没有高级查找代码生成的
FetchXml
差,并且它提供与 LINQ 提供程序相同的功能,同时提供完全非标准的查询接口(与LINQ)。至于 LINQ(非)功能,LINQ 提供程序的限制很明显,而且我认为相当不错,已记录。例如,您的
.Where(x => "b" == x)
代码段违反了where
子句限制:不是为 Microsoft 辩护:在 LINQ 提供程序达到专业级之前,他们需要在 LINQ 提供程序(阅读:直接到 SQL 提供程序)上投入大量工作,但是嘿,至少他们有一个很好的免责声明。
To build on Anwar's excellent answer focusing on LINQ vs. FetchXml, I'll add I never use
QueryExpression
. Why?So it's worse in querying power than
FetchXml
without the Advanced Find code generation, and it offers the same functionality as the LINQ provider while offering a completely non-standard querying interface (unlike LINQ).As for LINQ (non)functionality, the limitations of the LINQ provider are clearly, and I think fairly well, documented. Your
.Where(x => "b" == x)
snippet, for instance, violates thewhere
clause restriction:Not defending Microsoft: they need to put in a lot of work on the LINQ provider (read: direct-to-SQL provider) before the LINQ provider is professional grade, but hey, at least they've got a great disclaimer.
在我看来,我通常根据需求选择 Linq 或 FetchXml。
对于 Linq:对于早期绑定,我喜欢使用 Linq,因为它是强类型的,并且它对开发速度有很大帮助,但正如您上面所说,它有其缺点。
对于 FetchXML:我真的很喜欢使用这个神奇的语句:
为什么?因为除了聚合和分组之外,它与使用 QueryExpression 非常相似。
我唯一讨厌 FetxhXML 的地方是它很难构建,这与 Linq 不同。
为了构建 FetchXML 查询,我必须打开 Advanced-Find,然后添加列,然后输入我的条件等等,最后我下载它并将其复制到我的代码中,等等。
最后,FetchXML 在其他方法中具有最少的限制。
关于性能,我尝试使用 StopWatch 在 Linq 和 FetchXML 之间对同一查询进行基准测试,结果是 FetchXML 比 Linq 更快。
In my opinion, I usually go for Linq or FetchXml depending for the requirements.
For the Linq: In case for early-bound, I like using Linq because it's strongly typed and It helps much for development speed, but as you stated above, it has its disadvantages.
For the FetchXML: I really love using this magic statement:
Why? Because it's very similar of using the QueryExpression in addition of the aggregation and grouping.
The only thing I hate about FetxhXML is that it's hard to build, unlike the Linq.
For building FetchXML queries, I have to open the Advanced-Find then add columns then put my criteria and so on, finally I download it and copy it into my code, and so on.
Finally, the FetchXML has the least limitations among the others.
Regarding the performance I've tried to benchmark between Linq and FetchXML for same query using StopWatch, the result was FetchXML is faster than the Linq.
客户特别要求我使用查询表达式模型,因此为了让我的生活更轻松,我向 IOrganizationService 添加了很多扩展方法。示例包括:
将params object[]和T实体类型转换为查询表达式,并自动将结果返回到实体列表。所以它是这样使用的:
我也经常使用这个:
这些类型的扩展方法使查询表达式的使用变得更加容易,为您提供了更多的 LINQ 类型风格,而没有容易陷入的奇怪的 linq 限制陷阱。
I've been asked specifically by a client to use the Query Expression model, so in order to make my life easier, I've resorted to adding a lot of extension methods to IOrganizationService. Examples Include:
which converts the params object[] and T entity type into a query expression, and automatically returns the results to an entity list. So it is used like so:
I also use this one a lot too:
These type of extension methods make working with query expressions a lot easier, giving you a much more LINQ type style, without weird linq restriction traps that are easy to fall into.
我提倡使用 FetchXML,因为我可以在 JavaScript 或 C# 代码中使用它,这与 LINQ 或 QueryExpression 不同......因此少了一件需要学习和维护的事情。至于像 Intellisense 这样的东西,有一个很棒的工具可以插入到 XrmToolbox 中,名为 FetchXML Builder,它在以下方面要复杂得多:设计比使用“高级查找”所见过的复杂查询。我已经在 CRM Online 客户端上使用它一个月了,它与在此环境中使用 SQL 非常接近。它还可以为我生成 QueryExpression 代码。我已将这个工具移交给我的业务分析师,他们将使用它为仪表板制作复杂的数据集 - 这对客户来说是一个巨大的胜利。
我确实对早期绑定无法检测错误感到遗憾,但我喜欢
I would advocate in favor of FetchXML because I can use it in my JavaScript or C# code, unlike LINQ or QueryExpression...therefore one less thing to learn and maintain. As for stuff like Intellisense, there is a great tool that plugs into XrmToolbox called FetchXML Builder that is much more sophisticated in designing complex queries than you will ever see using Advanced Find. I have been using it now for a month for a CRM Online client and it is as close to using SQL as you can get in this environment. It can also generate QueryExpression code for me. I have turned over this tool to my business analysts and they are going to town using it to make sophisticated data sets for the dashboard - a big win for the clients.
I do lament the loss of detecting errors with early binding, but I enjoy