LINQ 查询多个日期并计算行数

发布于 2024-10-25 04:54:10 字数 241 浏览 2 评论 0原文

你好,我想知道如何使用 LINQ 做两件事 这个问题可能更多是一个 SQL/C# 问题,我首先想查询多个日期 我该怎么做?

例如,我想在 DateTime SQL 列中查询 2011 年的每个日期,所以我想找到 01/01/2011 到 31/12/2011 我想我会用 ##/##/ 等内容替换第一天的月份数字2011

其次,我如何计算行数会像这样“var rowCount = qRows.Count();”

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十二 2024-11-01 04:54:10

试试这个:

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

            int Count = ord.Count;

try this :

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

            int Count = ord.Count;
手心的海 2024-11-01 04:54:10
from x in somethingwithdate
  where x.adate > '1/1/2000'
  where x.adate < '1/1/2010'
   select x

你也可以做 x.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

黄昏下泛黄的笔记 2024-11-01 04:54:10

您可以根据需要重复执行myDate.AddDays(1) 多次。

是的,您可以对返回的 LINQ 数据集执行 Count()。

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

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

公布 2024-11-01 04:54:10

与之前的答案略有不同(例如,如果您从另一个对象中提取日期):

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文