【发布时间】:2011-03-03 19:19:11
【问题描述】:
我正在使用 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 中,我确实很重要。例如,在一个列中,我计算在给定日期设置的约会数量,在另一列中,我计算在同一天参加的约会数量。 Date1 是指设置约会的日期,Date2 是指参加约会的日期。例如,在 2011 年 3 月 3 日,我设置了 4 个约会(这些约会的日期 1 是 2011 年 3 月 11 日),并且它们被设置为未来的不同日期(日期 2)。在同一天(这次是 3 月 3 日是 Date2),我还参加了过去在其他日期安排的其他几个约会。
感谢您的任何建议。
【问题讨论】:
标签: c# linq linq-to-sql