I want to return a count of new users since a specific date.
Users table has: UserID, username, dateJoined.
SELECT COUNT(USERID)
FROM Users
where dateJoined > @date
How would this look in linq-to-sql?
Can you use the keyword COUNT?
In LINQ, you can count the total number of elements present in the given sequence by using the Count Method. This method returns the total number of elements present in the given sequence.
The result of an executed LINQ query has a method Count() , which returns the number of elements it contains.
In LINQ to SQL, the data model of a relational database is mapped to an object model expressed in the programming language of the developer. When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution.
LINQ to DB is a data access technology that provides a run-time infrastructure for managing relational data as objects. linq2db.PostgreSQL. by: it ili LinqToDB. last updated a month ago. Latest version: 4.3.0.
You can go two routes:
var count = (from u in context.Users where u.datJoined > date select u).Count();
or
var count = context.Users.Where( x => x.datJoined > date).Count();
Both are equivalent, it really boils down to a matter of personal preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With