ab00764 ab00764 - 8 months ago 52
MySQL Question

Get min and max value from database Linq to Sql query in MVC?

here is my query that i have written in my controller

public ActionResult Description()
var firstId = from p in obj.Cubisms
where p.Id = MIN(Id)
select p;

but here "MIN" or "Max" gives error what should be the query if i am wrong


You can use Enumerable functions to do the same,

  var min = obj.Cubisms.Min(r=> r.Id);
  var max = obj.Cubisms.Max(r=> r.Id);