16
Vote

Enable a mechanism to provide query hints

description

Neither the Linq extensions to C# nor Entity Framework provides any way to pass a query hint to the underlying data provider. For database programming, this is a fundamental shortcoming of the Microsoft development stack. There is no way, on a per-query basis to pass a simple locking hint (NOLOCK, HOLDLOCK, etc.).
The only workaround is to use TransactionScope objects to fence specific code boundaries, which essentially executes SET ISOLATION statements on the connection. But there is no way, for example, to specify READPAST or FORCESEEK query options, which are essential to managing lock contention in high-volume systems. Obviously, this also means there is no way to provide index hints.

Short Term: Add a monadic With() function to Entity Framework to transmit query hints to Sql Server:
                            (from e in Db.ExtCompany.With(QueryHint.ReadPast) where e.Company == companyId select e).Any();

                                       Longer Term: Add a “with” keyword to C# for use in Linq to supply a query-provider-specific hint to the underlying provider:
                            (from e in Db.ExtCompany with ReadPast, ForceSeek where e.Company == companyId select e).Any();

file attachments

comments

davidlars99 wrote Feb 7 at 3:12 PM

It would be fantastic to add support for query/table hints. Our team has to shy away from EF because of this limitation..

RoMiller wrote Feb 20 at 5:22 PM

**EF Team Triage:** We agree that this would be a good scenario to enable. Taking into account where we are in the EF6 release along with the size and the impact of this feature our team is not planning to implement it in EF6. Therefore, we are moving it to the Future release to reconsider in the next release.

ZBo wrote May 10 at 5:21 PM

There are two work-arounds.

1) Use TransactionScope objects to execute SET ISOLATION statements on the connection.

2) Create a view and apply the join hints to the FROM clause inside the view. Example ViewWrapperTest.SQL attached.