开发者

linq query with condition

I'm writing a linq query in query syntax and I'm wondering how to add another where clause. Basically, I have the following:

var test = from t in MyDC.TheTable
           where t.UserID == TheUserID
           where t.DateDone.Date == TheDate.Date
           select new MyModel {.....};

TheTable has a column called LinkedID and this column is also in another table called ColorStatus (a number between 1 and 10). I'm looking to write the where clause "where the LinkedID in the ColorStatus tab开发者_如何学运维le is less than 7".

Thanks.


Just a suggestion on improving the statement you have. You can actually merge the two where conditions into a single one. && means "AND"

Where t.UserID == TheUserID && t.DateDone.Date = TheDate.Date


Your information "another table called ColorStatus" doesn't make sense here.

var test = from t in MyDC.TheTable
           where t.UserID == TheUserID
              && t.DateDone.Date == TheDate.Date
              && t.LinkedID < 7           
           select new MyModel {.....};

Probably I didn't get your idea, here is an example of join may help you.

var test = from t in MyDC.TheTable
           join x in MyDC.ColorStatus
           on t.LinkedID == x.LinkedID
           where t.UserID == TheUserID
              && t.DateDone.Date == TheDate.Date
              && x.AnotherField == 1
           select new MyModel {.....};
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜