如何在Linq to SQL中使用NOEXPAND提示? [英] How to use the NOEXPAND hint with Linq to SQL?

查看:171
本文介绍了如何在Linq to SQL中使用NOEXPAND提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个索引视图,我需要为其指定noexpand提示才能使其合理执行.不幸的是,从NOLOCK提示中将Linq修改为SQL生成的T-SQL查询时,似乎没有简单的方法可以直接利用这些提示,还是存在?

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?

我的想法是,允许通过使用属性或通过dbml声明性地自定义这些内容是有意义的.同样,由于Linq to SQL似乎只能以SQL Server为目标,因此,我们还能够利用这些高级功能(如果存在)是有道理的.不管采用哪种实现方式,我都对解决此问题的任何创造性方式都感兴趣.

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.

推荐答案

我找到了一种可行的解决方法,但需要为每个要使用NOEXPAND提示的SQL视图创建第二个视图.在第二个视图中,只需从原始视图中选择所有字段,然后在NOEXPAND提示上添加即可.现在,任何需要使用NOEXPAND提示的Linq to 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.

更多详细信息可以在在创建依赖视图时要考虑的一个缺点是,您必须确保以正确的依赖顺序应用创建脚本

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

有人有更好的选择吗?我宁愿不必为了支持使用此必要的优化程序提示而创建额外的SQL视图.

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.

这篇关于如何在Linq to SQL中使用NOEXPAND提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆