如何在 Linq to SQL 中使用 NOEXPAND 提示?

发布于 2024-09-07 00:22:40 字数 254 浏览 3 评论 0原文

我有一个索引视图,我需要指定 noexpand 提示才能使其合理执行。不幸的是,从 NOLOCK 提示修改 Linq to SQL 生成的 T-SQL 查询来看,似乎没有简单的方法可以直接利用这些提示,或者是吗?

我的想法是,允许通过使用属性或通过 dbml 以声明方式自定义这些内容是有意义的。此外,由于 Linq to SQL 似乎只适用于 SQL Server,因此我们也能够利用这些高级功能(如果存在)才有意义。不管实施如何,我对解决这个问题的任何创造性方法都很感兴趣。

I have an indexed view that I need to specify the noexpand hint for in order for it to perform reasonably. Unfortunately as seen with regard to modifying the Linq to SQL generated T-SQL query from the NOLOCK hint it appears that there is no easy way to take advantage of these hints directly or is there?

My thought is that it would make sense to allow customization of this stuff through the use of attributes or declaratively through the dbml. Also since Linq to SQL seems to only work targeting SQL Server it only makes sense that we are also able to leverage these advanced features (if they exists). Regardless of the implementation though I'm interested in any creative ways of solving this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谎言月老 2024-09-14 00:22:40

我找到了一种解决方法,它似乎有效,但需要为每个想要使用 NOEXPAND 提示的 SQL 视图创建第二个视图。在第二个视图中,只需选择原始视图中的所有字段并添加 NOEXPAND 提示即可。任何需要使用 NOEXPAND 提示的 Linq to SQL 查询现在都可以仅定位包装原始视图的视图。

更多详细信息,请参阅此MSDN 帖子

创建依赖视图时要考虑的一个缺点是,您必须确保以正确的依赖顺序应用创建脚本

是否有人有更好的替代方案?我宁愿不必创建额外的 SQL 视图来支持这个必要的优化器提示的使用。

I've found a workaround which appears to work but requires making a second View for each SQL View that one would want to use the NOEXPAND hint with. In the second view just select all of the fields from the original view and tack on the NOEXPAND hint. Any Linq to SQL query that needs to use the NOEXPAND hint can now just target that view that wraps the original.

More details can be found in this MSDN post.

One down side among others to consider when creating dependent views is that you will have to make sure to apply the creation scripts in the proper dependency order

Does anybody have any better alternatives? I would rather not have to create extra SQL Views just to support usage of this necessary optimizer hint.

作死小能手 2024-09-14 00:22:40

我完全同意,但我不相信有这样的方法。在 EF4 中,您可以使用 ExecuteStoreCommand 来直接执行 SQL。如果性能不可接受,这可能是您唯一的选择。

==编辑==

您还可以在 LINQ to SQL 中通过 ExecuteQuery 方法执行此操作。

http://msdn.microsoft.com/en-us/library/bb399403。 ASPX

I totally agree, but I do not believe there is such a method. In EF4 you can use the ExecuteStoreCommand that will let you execute SQL directly. That may be your only option if performance is unacceptable.

==EDIT==

You can also do this in LINQ to SQL through the ExecuteQuery method.

http://msdn.microsoft.com/en-us/library/bb399403.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文