Alan Alan - 2 months ago 8
C# Question

Is there a way that I can get a count of rows with a LINQ statement?

I have been using this LINQ statement:

var phrases = await db.Phrases
.AsNoTracking()
.ToListAsync();


But what I need is to get a count of the number of rows in Phrases.

I have never used LINQ to do this before. Is there a way that I can do this?

Answer

The sync version:

var phrasesCount = db.Phrases.Count();

The async version (assuming this is EF):

var phrasesCount = await db.Phrases.CountAsync();