开发者

Parenthesis Expressions in LINQ to SQL

If I want to generate the query (month(created) = 1 and year(created) = 2010) or (month(modified) = 1 and year(modified) = 2010) with linq, how would I go about it?

I have o.Created.Value.Month == month && o.Created.Value.Year == year. If I do (o.Creat开发者_运维技巧ed.Value.Month == month && o.Created.Value.Year == year) || (o.Modified.Value.Month == month && o.Modified.Value.Year == year) wouldn't the parenthesis just be ignored?


No, the parentheses won't be ignored by LINQ - they're important to indicate the logic. They're effectively present in the expression tree, in that you'll end up with an "OR" expression with two subexpressions each of which is an "AND" expression.

The query you've given should be fine - have you tried it, and checked the resulting SQL?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜