我对我的过滤器使用了这个hql查询。查询完美工作,除了宽度(字符串)部分。HQL查询问题
下面是该查询,
public IList<ColorGroup> GetDistinctColorGroups(int typeID, int finishID, string width)
{
string queryStr = "Select distinct c from ColorGroup c inner join c.Products p " +
"where p.ShowOnline = 1 ";
if (typeID > 0)
queryStr += " and p.ProductType.ID = " + typeID;
if (finishID > 0)
queryStr += " and p.FinishGroup.ID = " + finishID;
if (width != "")
queryStr += " and p.Size.Width = " + width;
IList<ColorGroup> colors = NHibernateSession.CreateQuery(queryStr).List<ColorGroup>();
return colors;
}
ProductType和大小都相同的映射关系和。
这是错误;
NHibernate.QueryException:邻近收集非法 语法:尺寸[选择从.Domain.ColorGroup 不同C C 内部联接c.Products p其中 p.ShowOnline = 1和p.ProductType.ID = 1和p.FinishGroup.ID = 5和p.Size.Width = 4]
任何想法?
编辑:
顺便说一下在这个项目中我用这个LINQ查询这实在是simmilar HQL之一。因此,我不认为这是一个misstype或者更根本的错误..
colorOfSerie = (from p in products where p.Size.Width.Equals(width) select p.ColorGroup).Distinct().ToList<ColorGroup>();
如果删除宽度条件,查询是否运行,即不会引发错误? – 2010-04-22 08:46:28
是的,它正在处理它。 – ygit 2010-04-22 08:48:31