views:

78

answers:

3

I'm trying to write a LINQ query that that simply gets the count of rows where a variable ('id') is equal to the JOB_GROUP statement. Problem is, Visual Studio is returning an error on the ; at the end, saying 'Only assignment calls.....may be used as a statement'. Is there anything obvious wrong with my query?

var noofrows = from s in dc.QRTZ_JOB_DETAILs 
                where id == s.JOB_GROUP
               select s.JOB_NAME.Count();
+13  A: 

You need to wrap the linq query around parentheses before calling the Count() method.

var noofrows = (from s in dc.QRTZ_JOB_DETAILs 
                where id == s.JOB_GROUP 
                select s.JOB_NAME).Count();
Equiso
+5  A: 

More lightweight, and readable:

 var count = dc.QRTZ_JOB_DETAILs.Count(x=>id == x.JOB_GROUP );
Nix
A: 

Alternatively, you could simply write:

var noofrows = dc.QRTZ_JOB_DETAILs.Count(s => id == s.JOB_GROUP);
nikie