ab00764 ab00764 - 1 year ago 99
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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download