0

Hi I want to know how to do two things with LINQ This question is probably more a SQL/C# thing I firstly want to query with multiple dates How would I do this?

For example I want to query every date in 2011 in a DateTime SQL Column So I want to find 01/01/2011 to 31/12/2011 I guess I would replace the first day month numbers with something e.g ##/##/2011

Secondly how do I count rows would it be like this "var rowCount = qRows.Count();"

Thanks

1
  • You answered your second question yourself. +10! Commented Mar 23, 2011 at 21:45

4 Answers 4

3

try this :

List<Order> ord = (from o in dc.Orders
                               where o.OrderDate.Value.Year == 2011
                               select o).ToList();

            int Count = ord.Count;
Sign up to request clarification or add additional context in comments.

1 Comment

your solution does work, but it is better to use a between style query so that the database can use any indexes. This can make a massive difference if there are lots of rows
0

You can do myDate.AddDays(1) repeated as many times as necessary.

Yes, you can do a Count() on the returned LINQ dataset.

Comments

0
from x in somethingwithdate
  where x.adate > '1/1/2000'
  where x.adate < '1/1/2010'
   select x

you can also do x.Count

Comments

0

Slightly different take on earlier answer(if you were pulling the date from another object for instance):

              DateTime myDate = new DateTime(2011,1,1);
                var results = (from t in dc.events
                               where t.event_date.Value.Year.Equals(myDate.Year)
                               select t).ToList();
                int testCount = results.Count();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.