NHibernate与全文检索
NHibernate似乎还没有全文检索的语句吧,我常用两种方式
1.ICriteria,使用Expression.Sql
ICriteria cri = this.Session.DbSession.CreateCriteria(typeof(Mag.Article.LightNews));
cri.Add(Expression.Eq("Deleted", IsDelete));
cri.Add(Expression.Sql(string.Format("contains(title,'{0}')", key)));
2.ISQLQuery
string sql = string.Format("select id from [user] where contains(loginname,'{0}')", pKey);
ISQLQuery query = this.Session.DbSession.CreateSQLQuery(sql);
query.AddScalar("id",NHibernateUtil.Int32);
System.Collections.ArrayList ids = new System.Collections.ArrayList();
query.List(ids);//也可query.List<Entity.TypeName>,当然sql语句就不能指定字段