ab00764 ab00764 - 3 months ago 33
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

Answer

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);