SQL:
select *
from INVOICE inv WITH(NOLOCK)
inner join ERP_TRANSACTION erpt WITH(NOLOCK) on inv.Id = erpt.Id
inner join ERP_TRANSACTION_LOG erptl WITH(NOLOCK) on inv.InvoiceId = erptl.FimId
Linq:
from inv in _invoiceService.QueryableAsNoTracking()
join erpt in _erpTransactionService.QueryableAsNoTracking() on inv.Id = erpt.Id
join erpt1 _erpTransactionLogService.QueryableAsNoTracking() on inv.InvoiceId = erptl.FimId
select new Model {}
我正试图将SQL查询转换为linq查询,但我无法找到与WİTH(NOLOCK)
等效的linq。
您实际上需要使用;IsolationLevel.ReadUncommitted";。这意味着查询不在乎内容是否正在被写入到它正在读取的行中——它会读取";脏的";数据,并将其作为结果集的一部分返回。
using (var txn = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadUncommitted
}
))
{
// Your LINQ to SQL query goes here
}
链接到原始帖子-链接