简体   繁体   中英

LINQ to SQL advice - why won't it work?

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();

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();

更轻巧,更易读:

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

或者,您可以简单地编写:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM