【发布时间】:2011-02-10 23:02:56
【问题描述】:
我将这个 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 和 Size 具有相同的映射和关系。
这是错误;
NHibernate.QueryException:非法 集合附近的语法:Size [Select 与 .Domain.ColorGroup c 不同的 c 内连接 c.Products p where p.ShowOnline = 1 和 p.ProductType.ID = 1 和 p.FinishGroup.ID = 5 和 p.Size.Width = 4]
有什么想法吗?
编辑:
顺便说一句,在这个项目中,我使用了这个 linq 查询,它与 hql 非常相似。所以我不认为这是一个错误类型或更根本的错误..
colorOfSerie = (from p in products where p.Size.Width.Equals(width) select p.ColorGroup).Distinct().ToList<ColorGroup>();
【问题讨论】:
-
如果删除宽度条件,查询是否运行,即不会引发错误?
-
是的,没有它也可以工作。
标签: c# nhibernate hql