Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get last 10 mins records using linq?

Tags:

c#

sql

asp.net

linq

I want to write LINQ query from last 10 mins inserted records from table. How do I write it? Please help me.

Below is my SQL query:

SELECT AccountNumber, OrderID,RechargeDate 
FROM    OrderItem OI
WHERE RechargeStatus = 'SUCCESS' 
  AND AccountNumber ='" + AccountNumber + "' and DateADD(minute, -10,getdate() ) < RechargeDate  AND OrderItemID <> " + OrderItemID + "";

Now, I want to rewrite the query above using LINQ.

like image 297
Anil Kumar Avatar asked Oct 04 '15 06:10

Anil Kumar


1 Answers

You need to use Where linq extension method.

db.OrderItems.Where(x => x.RechargeStatus.Equals("SUCCESS") && 
                         x.AccountNumber == strAccountNumber &&
                         x.RechargeDate > DateTime.Now.AddMinutes(-10) &&
                         x.OrderItemID != OrderItemID )
like image 180
Sateesh Pagolu Avatar answered Oct 20 '22 04:10

Sateesh Pagolu