linq where statement with OR

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.


using (MyDataContext TheDC = new MylDataContext())
{
   var TheOutput = from a in TheDC.MyTable
     where a.UserID == TheUserID &&   
     (a.Date1.Month == TheDate.Month && a.Date1.Year == TheDate.Year)
     ||
     ( a.Date2.Month == TheDate.Month && a.Date2.Year == TheDate.Year)
     group a by a.Date1.Date AND by a.Date2.Date into daygroups
     select new MyModel{...};

尝试删除4个额外的“where”并将OR更改为||。

链接地址: http://www.djcxy.com/p/31908.html

上一篇: linq group通过:良好的语法,但奇怪的输出

下一篇: linq where语句与OR