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();