0

I have below SQL query trying to convert it to LINQ:

if exists(select top 1'x'     
          from tblCallerDetails    
          where cId = @cId   
            and bId = @bId   
            and pId = @pid    
            and isnull(acId, 0) = isnull(@acId, 0)    
            and ltrim(rtrim(CallerId)) = @CallerID    
            and isnull(convert(date, CallerDate), '2001-1-1') = isnull(convert(date, @CallerReceivedDt), '2001-1-1')     
            and isnull(Dialled, 0) != 1)    
            and ltrim(rtrim(isnull(@CallerStatus, ''))) != 'CANCELLED' 
begin    
    -- blah blah 
end

My LINQ statement:

return (bool)(_Context?.tblCallerDetails.Any
            (x =>
                x.cId == cId
            && x.bId == bId
            && x.pId == pId
            && x.acId == acId
            && x.calledId == callerId
            && x.CallerDate == @CallerReceivedDt
            && x.Dialled != true
            && !x.CallerStatus.Equals(CallerStatusType.DIALLED.ToString())
            ));

I need to check for the null condition tried using NULL coalescing op getting compilation error, I wanted to achieve this in a single line of LINQ method syntax if possible.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Does this answer your question? [Linq where column == (null reference) not the same as column == null](https://stackoverflow.com/questions/2097539/linq-where-column-null-reference-not-the-same-as-column-null) also https://stackoverflow.com/questions/586097/compare-nullable-types-in-linq-to-sql – Charlieface May 14 '23 at 10:58

0 Answers0