今天小蒋告诉我NHibernate在配置了many-to-one的关系后查询时出现灵异现象!HQL语句是这样写的:
From Product p where p.ProductName ='11' or p.Category.CategoryName='1'
跟踪出来的sql是这样的:
select product0_.Id as Id2_, product0_.ProductName as ProductN2_2_, product0_.SerialNumber as SerialNu3_2_, product0_.ModelNumber as ModelNum4_2_, product0_.IncomePrice as IncomePr5_2_, product0_.Quantity as Quantity2_, product0_.Stock as Stock2_, product0_.Remark as Remark2_, product0_.CreateDate as CreateDate2_, product0_.CategoryId as CategoryId2_ from Products product0_, ProductCategories productcat1_ where (product0_.ProductName='11' )or(productcat1_.CategoryName='1' and product0_.CategoryId=productcat1_.Id)
发现在用了OR条件之后无论在1.0或者2.0的NHibernate中都会出现此问题,不知道到其他人是否也遇到过类似问题,是否有解决的办法?高手路过时希望能指点一二,谢谢。。。
From Product p where p.ProductName ='11' or p.Category.CategoryName='1'
跟踪出来的sql是这样的:
select product0_.Id as Id2_, product0_.ProductName as ProductN2_2_, product0_.SerialNumber as SerialNu3_2_, product0_.ModelNumber as ModelNum4_2_, product0_.IncomePrice as IncomePr5_2_, product0_.Quantity as Quantity2_, product0_.Stock as Stock2_, product0_.Remark as Remark2_, product0_.CreateDate as CreateDate2_, product0_.CategoryId as CategoryId2_ from Products product0_, ProductCategories productcat1_ where (product0_.ProductName='11' )or(productcat1_.CategoryName='1' and product0_.CategoryId=productcat1_.Id)
发现在用了OR条件之后无论在1.0或者2.0的NHibernate中都会出现此问题,不知道到其他人是否也遇到过类似问题,是否有解决的办法?高手路过时希望能指点一二,谢谢。。。