带命名参数的nhibernate hql
我使用Castel Active Record实现了一个搜索功能。我原以为代码很简单,但我一直觉得 NHibernate.QueryParameterException:找不到命名参数[searchKeyWords] 错误。有人能告诉我出了什么问题吗?非常感谢带命名参数的nhibernate hql,nhibernate,hql,castle-activerecord,Nhibernate,Hql,Castle Activerecord,我使用Castel Active Record实现了一个搜索功能。我原以为代码很简单,但我一直觉得 NHibernate.QueryParameterException:找不到命名参数[searchKeyWords] 错误。有人能告诉我出了什么问题吗?非常感谢 public List<Seller> GetSellersWithEmail(string searchKeyWords) { if (string.IsNullOrEmpty(sea
public List<Seller> GetSellersWithEmail(string searchKeyWords)
{
if (string.IsNullOrEmpty(searchKeyWords))
{
return new List<Seller>();
}
string hql = @"select distinct s
from Seller s
where s.Deleted = false
and ( s.Email like '%:searchKeyWords%')";
SimpleQuery<Seller> q = new SimpleQuery<Seller>(hql);
q.SetParameter("searchKeyWords", searchKeyWords);
return q.Execute().ToList();
}
公共列表GetSellersWithEmail(字符串搜索关键字)
{
if(string.IsNullOrEmpty(searchKeyWords))
{
返回新列表();
}
字符串hql=@“选择不同的
来自卖方
其中s.Deleted=false
和(像“%:searchKeyWords%”这样的电子邮件);
SimpleQuery q=新的SimpleQuery(hql);
q、 SetParameter(“searchKeyWords”,searchKeyWords);
返回q.Execute().ToList();
}
为什么不传递带参数的%字符
string hql = @"select distinct s
from Seller s
where s.Deleted = false
and ( s.Email like :searchKeyWords)";
SimpleQuery<Seller> q = new SimpleQuery<Seller>(hql);
q.SetParameter("searchKeyWords", "%"+searchKeyWords+"%");
return q.Execute().ToList();
string hql=@“选择不同的
来自卖方
其中s.Deleted=false
和(如电子邮件:搜索关键词)”;
SimpleQuery q=新的SimpleQuery(hql);
q、 SetParameter(“searchKeyWords”、“%”+searchKeyWords+“%”);
返回q.Execute().ToList();
我尚未确认您的解决方案,但我从中得到了类似的答案,并且该解决方案有效。所以,我想你的也是对的。非常感谢。