As other stated, this should be a 0 check.
Now, if your question is "can I avoid to do 2 enumeration if I end up in the second case", the answer is yes:
(int idCount, int guidCount) = dbContext.Documents.Aggregate((0, 0), ((int id, int guid) acc, Document doc)
=> (acc.id + (doc.Id == id ? 1 : 0), acc.guid + (doc.Guid == guid ? 1 : 0)));
docCount = idCount != 0 ? idCount : guidCount;
which only iterates the documents once.
Is this more readable? ... no. Slightly more performant and readable:
int idCount = 0;
int guidCount = 0;
foreach (var document in dbContext.Documents)
{
if (document.Id == id)
idCount++;
if (document.Guid == guid)
guidCount++;
}
docCount = idCount != 0 ? idCount : guidCount;
Is it worth it? It depends of your data. If enumerating your documents is a hot path that you have identified after proper benchmarking and is the best improvement you can make in your codebase/architecture (for example, hundred of millions of documents on a distant database, with no copy on local program, and this count is run often), then yes.
Otherwise, this is premature optimization, stick with your solution, with 0 instead of null.
docCountbenull?Enumerable.Countmight return 0 but it's not going to returnnull