带有命名参数的nhibernate hql

Wei*_* Ma 8 nhibernate castle-activerecord hql

我使用Castel Active Record实现了搜索功能.我认为代码很简单,但我一直在努力

NHibernate.QueryParameterException:无法找到命名参数[searchKeyWords]

错误.谁能告诉我出了什么问题?太感谢了.

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();
        }
Run Code Online (Sandbox Code Playgroud)

nay*_*kam 15

你为什么不用参数传递%字符?

   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();
Run Code Online (Sandbox Code Playgroud)