将 MAXDOP 添加到 Linq to Entities
我正在寻找 linq toEntity 扩展,它允许将 OPTION(MAXDOP x) 添加到生成的查询中。对于查询,我想限制它们的 SQL Server 资源。
比如:
Customers.WithMaxDop(2).Where(...) ..
找不到。 在我尝试深入创建自己的扩展之前,我想先向你们寻求帮助 - 你们建议如何这样做?
谢谢!
I was looking for linq to entities extension 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即查询提示不能通过扩展方法添加。您必须构建全新的 EF 提供程序,或者将带有提示的查询包装到数据库视图中,并将该视图映射为新的只读实体。
EF 是数据库(理论上任何数据库)之上的抽象 - 它不应该为您提供对此类数据库详细信息的控制。如果您需要这些详细信息,则必须在数据库层对它们进行编码,并且仅向 EF 公开视图或存储过程。
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.
现在 EF Core 3.x 似乎可以实现这一点。
您可以在操作之前和/或之后在低级别“拦截数据库操作”。在微软提供的示例中,他们在查询末尾添加了提示。
但是,我不知道每个操作是否都会发生这种情况,或者您是否可以仅对选定的命令应用这些拦截。
更多信息请参见:https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.x/#interception-of-database-operations
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.
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