本文介绍了如何获得以某个字母开头的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似于下面的方法,我需要返回所有以我传入的字母开头的组:
I have a method similar to the following, which I need to return all Groups that begin with the letter I'm passing in:
public IList<CompanyGroupInfo> GetGroupByQuery(string letter)
{
IList<CompanyGroupInfo> result = null;
result = _session
.CreateCriteria<CompanyGroupInfo>()
.Add(SqlExpression.Like<CompanyGroupInfo>(g => g.Name, letter))
.List<CompanyGroupInfo>();
return (result.Count > 0) ? result[0] : null;
}
我是 NHibernate 的新手,所以我真的不知道在这里做什么.在我看来,如果有一个 SqlExpression.StartsWith
方法是理想的,但没有.是否像修改表达式一样简单,以便
I'm brand new to NHibernate, so I don't really know what to do here. In my mind, it'd be ideal if there was a SqlExpression.StartsWith
method, but there isn't. Is it as simple as modifying the expression so that
.Add(SqlExpression.Like<CompanyGroupInfo>(g => g.Name, letter))
变得像
.Add(SqlExpression.Like<CompanyGroupInfo>(g => g.Name.StartsWith(letter)))
有人能指出我正确的方向吗?谢谢
Can somebody please point me in the right direction? Thanks
推荐答案
只看文档,我怀疑你想要:
SqlExpression.Like<CompanyGroupInfo>(g => g.Name, letter, MatchMode.Start)
但我很久没有使用 NHibernate...
but I haven't used NHibernate for ages...
这篇关于如何获得以某个字母开头的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!