0

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 {}

I'm trying to convert my SQL query to a linq query but I couldn't figure out the linq equivalent of WİTH(NOLOCK).

Charlieface
  • 29,562
  • 5
  • 12
  • 30

1 Answers1

1

You effectively need to use a "IsolationLevel.ReadUncommitted". It means that the query doesn't care if stuff is in the process of being written to the rows it's reading from - it'll read that "dirty" data and return it as part of the result set.

using (var txn = new TransactionScope(
    TransactionScopeOption.Required, 
    new TransactionOptions
    {
        IsolationLevel = IsolationLevel.ReadUncommitted
    }
))
{
    // Your LINQ to SQL query goes here
}

Link to original post - Link