开发者

LINQ querying for multiple dates and counting rows

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 i开发者_如何学JAVAn 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


try this :

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

            int Count = ord.Count;


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

you can also do x.Count


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

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


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();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜