开发者

Adding MAXDOP to Linq to Entities

I was looking for linq to entities exte开发者_StackOverflow中文版nsion which allows to add OPTION(MAXDOP x) to the query generated. For queries I want to limit their SQL Server resources.

Something like:

Customers.WithMaxDop(2).Where(...) ..

Couldn't find. Before I try to dig-in to create my own extension I wanted to ask you guys first for help - how would you suggest to do so?

Thanks!


That is query hint which cannot be added by extension method. You must either build whole new EF provider or wrap the query with the hint into database view and map the view as the new read only entity.

EF is abstraction on top of database (theoretically any database) - it is not supposed to offer you control over such DB details. If you want these details you must code them on database layer and only expose views or stored procedures to EF.


It seems that it is now possible with EF Core 3.x. You can "Intercept Database operetation" at a low level, before and/or after the operation. In the example provided by Microsoft, they added an hint at the end of the query.

command.CommandText += " OPTION (OPTIMIZE FOR UNKNOWN)";

However, I don't know if this will occur for each and any operation, or if you can apply those interceptions only on selected commands. More info here: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.x/#interception-of-database-operations

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜