WebDec 16, 2011 · LINQ var lastFiveProducts = (from p in products orderby p.ProductDate descending select p).Take (5); Lambda var lastFiveProducts = products.OrderByDescending (p => p.ProductDate).Take (5); Which ever you prefer. Share Improve this answer Follow answered Dec 16, 2011 at 10:23 James 79.7k 18 163 236 WebJun 7, 2011 · 15. I have this: var result = (from t in MyDC where t.UserID == 6 orderby t.UpdateTime select t.ID).Last (); Basically, I'm using Linq-to-Sql and it doesn't support the .Last operator. I could retrieve all the records of the user and then using linq to objects to get my value but I'm wondering how to do this with linq-to-sql and return only one ...
c# - How to select only the records with the highest date in LINQ ...
WebAug 24, 2024 · You only want the first one when ordered by the Id in descending order. [HttpGet] public int GetStudentId () { var latestStudentRecord = _context.StudentModel .OrderByDescending (a => a.Id) .First (); // return only the Id property of the latest record return latestStudentRecord.Id; } WebOct 4, 2015 · 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. c# sql asp.net linq Share Improve … oval charm sword and shield
c# - Checking if database column contains, starts with or ends …
WebI have a LINQ query to find records for the last 7 days which works fine No, you have a query that returns the calories burned more than 7 days ago (ie 8, 9, 10, etc). The way you structured your query, the correct way would be w.Date >= DateTime.Now.AddDays (-n) to get the last n days. Share Improve this answer Follow WebAug 14, 2012 · Have a look at the list of Supported and Unsupported LINQ Methods. Last () is not supported, but First () is, so you can just go on and reverse your ordering and use First () instead of Last (). mf => mf.AuditItems.OrderByDescending (ai => ai.DateOfAction).First ().Step == 1); Share Improve this answer Follow edited Aug 14, … Web32 minutes ago · Get table without DbSet. Can I get table without DbSet ? I need to record table from Stored Procedure to an object or can I record via view ? I use EF Core 6 and _context.DataBase.SqlQuery ("...").ToList - not fount method "SqlQuery". Know someone who can answer? raju gari gadhi full movie online watch