带 OR 的 linq where 语句
我正在使用 linq-to-sql 进行如下查询:
public static List<MyModel> GetData(int TheUserID, DateTime TheDate)
using (MyDataContext TheDC = new MyDataContext())
{
var TheOutput = from a in TheDC.MyTable
where a.UserID == TheUserID
(where a.Date1.Month == TheDate.Month && where a.Date1.Year == TheDate.Year)
OR
(where a.Date2.Month == TheDate.Month && where a.Date2.Year == TheDate.Year)
group a by a.Date1.Date AND by a.Date2.Date into daygroups
select new MyModel{...};
如何编写此代码以使 OR 和 AND 语句起作用?我试过放一个||和一个 &&到位,但它不起作用,我陷入了这个查询。
基本上,它应该返回一个月内的天数列表,并且在 MyModel 中,我进行计数。例如,在一列中,我计算在给定日期设置的约会数量,在另一列中,我计算同一天参加的约会数量。日期 1 指安排约会的日期,日期 2 指出席约会的日期。例如,在 2011 年 3 月 3 日,我设置了 4 个约会(日期 1 是 2011 年 3 月 11 日),并且它们被设置为未来的各个日期(日期 2)。在同一天(3 月 3 日是 Date2),我还参加了过去在其他日期安排的几个其他约会。
感谢您的任何建议。
I'm using linq-to-sql for a query like this:
public static List<MyModel> GetData(int TheUserID, DateTime TheDate)
using (MyDataContext TheDC = new MyDataContext())
{
var TheOutput = from a in TheDC.MyTable
where a.UserID == TheUserID
(where a.Date1.Month == TheDate.Month && where a.Date1.Year == TheDate.Year)
OR
(where a.Date2.Month == TheDate.Month && where a.Date2.Year == TheDate.Year)
group a by a.Date1.Date AND by a.Date2.Date into daygroups
select new MyModel{...};
How do I write this to make the OR and the AND statement work? I've tried putting a || and a && in place but it doesn't work and I'm stuck on this query.
Basically, it should return a list of days within a month and in the MyModel, I do counts. For instance, in a column I count the number of appointments set on a given day and in another column I count the number of appointments attended on the same day. Date1 refers to the date the appointments are set and Date2 refers to the dates the appointments are attended. So for example, on March 3rd 2011, I've set 4 appointments (Date1 is 3/11/2011 for these) and they're set for various dates in the future (Date2). During the same date (March 3rd is Date2 this time), I've also attended several other appointments that were set on other dates in the past.
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试删除 4 个额外的“where”并将 OR 更改为 ||。
Try removing the 4 extra "where" and change the OR to ||.