I am trying to convert an SQL query to Linq
The query is :
SELECT Distinct(InvoiceID)
FROM Invoices
WHERE ((DATEDIFF(day, InvoiceDate, GETDATE()) > PaymentDays) AND
status= 'false')
I have written the following code but not getting proper result....
var outstanding = db.Invoices.Where(t =>
(t.InvoiceDate.Value.Subtract(DateTime.Today)).Days > t.PaymentDays.Value
&& !(bool)t.Status)
In my opinion, DATEDIFF doesnt have proper equivalent in LINQ to SQL
I see a few problems with the code you've written.
DateTime.Subtract, for this sort of operation you'll need SqlMethods.DateDiffDay docs.bool.Parse or just compare to the string "false" as you did in your original. .Select(t => t.InvoiceID).Distinct() to your LINQ.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With