zosim
zosim

Reputation: 2979

How to get count with using COUNT_BIG() from Entity Framework

I want to call COUNT_BIG function over my table. This table returns a lot of data (bigint). I'm finding a way how can I call this function from EF. Until now I have a following code:

var qStr = @"SELECT COUNT_BIG() FROM Attachment"; 
var attachmentCountQuery = context.CreateQuery<long>(qStr);

But I don't know how to get the long variable from this query?

Or is there exists another way how to get the total count of the records from table, where count is bigint?

thanks

Upvotes: 1

Views: 640

Answers (1)

aF.
aF.

Reputation: 66697

Seeing here you are missing some code on that select.

You need to specify which field (expression) to count.

Something like:

var qStr = @"SELECT COUNT_BIG(column_from_Attachment_table) FROM Attachment"; 
var attachmentCountQuery = context.CreateQuery<long>(qStr);

Upvotes: 1

Related Questions