开发者

Parenthesis Expressions in LINQ to SQL

开发者 https://www.devze.com 2023-03-15 10:55 出处:网络
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?

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

精彩评论

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