Your query is not returning any ids. That is why the exception. If your id type is int? then use DefaultIfEmpty() like:
var value = _sequenceTemplateItemService.Query(e => e.templateId == templateid && e.contentItemId == contentid)
.Select(t => t.id)
.DefaultIfEmpty()
.Max();
The other options is to check for Any records and then return Max or null.
var tempResult = _sequenceTemplateItemService.Query(e => e.templateId == templateid && e.contentItemId == contentid)
.Select(t => t.id);
if (tempResult.Any())
{
return tempResult.Max();
}
else
{
return null;
}