How do I do this in Linq

D

David

Hi,

Sample query... how do I write it in linq?

SELECT UserName, COUNT(UserName) AS Expr1
FROM aspnet_Users
WHERE (LastActivityDate BETWEEN '23 March 2009' AND '10 April 2009')
GROUP BY UserName

I have tried...


var users = from Users in dc.aspnet_Users
where Users.LastActivityDate >= "23 March 2009"
where Users.LastActivityDate <= "10 April 2009"
group Users by Users.UserName into g
select new
{
Key = g.Key, Count = g.Count()
};

but it doesn't work. (problem with >= and <=)

I am new to linq (still attempting to get my head around it). I am not even
sure if g.Key and g.Count() are what I am looking for. All I know is I want
to be able to return a resultset like the sample query.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
M

Martin Honnen

David said:
However, I have key and count, what if I want to select more items in my
initial select or have further counts?

counts of what exactly? Currently, with

var users = from Users in dc.aspnet_Users

group Users by Users.UserName into g
select new
{
Key = g.Key, Count = g.Count()
};

you count the items in each group g.
 
D

David

so, if I do something like...

group Users by Users.UserName into g
group Users by Users.LoweredUserName in h

I can then do h.Key and h.Count() as well as g.Key and g.Count() in select?

(I am getting a bit ahead of myself here... but is the theory there?)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top