0

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 != )
Kirk Larkin
  • 84,915
  • 16
  • 214
  • 203
user8107351
  • 367
  • 4
  • 20
  • So, post your repository interface and UOW also. Without that I can not understand how you made your life more difficult. – Svyatoslav Danyliv Feb 09 '21 at 12:28
  • Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) might help you. – NetMage Feb 09 '21 at 19:03

1 Answers1

1

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 )