How to use the NOEXPAND hint with Linq to SQL?

和自甴很熟 提交于 2019-12-05 07:19:53

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!