使用linq-to-sql返回计数 [英] Return a count with linq-to-sql
本文介绍了使用linq-to-sql返回计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想返回自特定日期以来的新用户数.
I want to return a count of new users since a specific date.
Users表具有:UserID,用户名,dateJoined.
Users table has: UserID, username, dateJoined.
SELECT COUNT(USERID)
FROM Users
where dateJoined > @date
这在linq-to-sql中看起来如何?
How would this look in linq-to-sql?
可以使用关键字COUNT吗?
Can you use the keyword COUNT?
推荐答案
您可以走两条路线:
var count = (from u in context.Users where u.datJoined > date select u).Count();
或
var count = context.Users.Where( x => x.datJoined > date).Count();
两者都是等效的,实际上归结为个人喜好.
Both are equivalent, it really boils down to a matter of personal preference.
这篇关于使用linq-to-sql返回计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文