开发者

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 stateme开发者_Python百科nt. 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();


More lightweight, and readable:

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


Alternatively, you could simply write:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜