Alan Alan - 1 year ago 79
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

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 Source

The sync version:

var phrasesCount = db.Phrases.Count();

The async version (assuming this is EF):

var phrasesCount = await db.Phrases.CountAsync();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download