I am getting this error one of my projects.
InvalidOperationException: Sequence contains no elements.
here is my code in this I am trying to create auto-generated Id with string format.
public async Task<IActionResult> Create()
{
int id = _db.Patient.Max(item => item.Id)+1;
ViewBag.autoid = "BL0000"+id.ToString();
return View();
}
I resolved this issue
public async Task<IActionResult> Create()
{
//x = _db.Patient.Max(item => item.Id);
x=_db.Patient.DefaultIfEmpty().Max(item => item == null ? 1 : item.Id+1);
ViewBag.autoid = "BL0000"+x.ToString();
return View();
}