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.