now i'm using nhibernate 3.2 as the orm,when i write code like this:
PostReaderBll postReaderBll=new PostReaderBll();
var query = from p in postReaderBll.Query()
where (p.Post.Flag == (int)PostType.Post && p.Post.MailState == (int)MailState.Normal) || (p.ReceiveUser == LoginUser.UserIdentity && p.Post.Flag == (int)PostType.Mail && p.Post.MailState == (int)APSP.Form.MailState.Normal)
select p;
i get this sql:
SELECT TOP ( 10 /* @p0 */ ) ID1_70_,
IsRead2_70_,
ReceiveU3_70_,
ReadDate4_70_,
Flag5_70_,
Label6_70_,
PostID7_70_ FROM (select postreader0_.[ID] as ID1_70_,
postreader0_.[IsRead] as IsRead2_70_,
postreader0_.[ReceiveUser] as ReceiveU3_70_,
postreader0_.[ReadDate] as ReadDate4_70_,
postreader0_.[Flag] as Flag5_70_,
postreader0_.[Label] as Label6_70_,
开发者_如何学运维 postreader0_.[PostID] as PostID7_70_, ROW_NUMBER()
OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row
from PostReader postreader0_
inner join Post post1_
on postreader0_.[PostID] = post1_.[ID]
where post1_.[Flag] = 1 /* @p1 */
and post1_.[MailState] = 0 /* @p2 */
or postreader0_.[ReceiveUser] = 'admin' /* @p3 */
and post1_.[Flag] = 0 /* @p4 */
and post1_.[MailState] = 0 /* @p5 */) as query WHERE query.__hibernate_sort_row > 0 /* @p6 */ ORDER BY query.__hibernate_sort_row
but i need the where like this:
( post1_.[Flag] = 1 /* @p1 */
and post1_.[MailState] = 0 /* @p2 */)
or (postreader0_.[ReceiveUser] = 'admin' /* @p3 */
and post1_.[Flag] = 0 /* @p4 */
and post1_.[MailState] = 0 /* @p5 */)
It is the same because, OR operators are always evaluated after AND operators.
Reference documentation for OR operator:
Combines two conditions. When more than one logical operator is used in a statement, OR operators are evaluated after AND operators. However, you can change the order of evaluation by using parentheses.
http://msdn.microsoft.com/en-us/library/ms188361.aspx
精彩评论