Skip to content
Advertisement

How do I convert this SQL into LINQ?

How Do I convert this sql query:

select * from Trades where tradestatus = 1 and tradetype = 1 and maturitydate < GETDATE() and referenceId not in (select referenceid from Trades where tradetype = 2)

to LINQ.

I got stuck at this point:

_unitOfWork.TreasuryBillsRepository.Find(t => t.TradeStatus == 1 && t.MaturityDate < DateTime.Now && t.ReferenceId != )

Advertisement

Answer

I think you must write like this:

 _unitOfWork.TreasuryBillsRepository.Find(t => t.TradeStatus == 1 && t.MaturityDate < DateTime.Now && _unitOfWork.ReferenceRepository.Where(r=>r.tradetype = 2).Select(r=>r.ReferenceId ).Contains(t.ReferenceId) == false )
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement