是否可以向实体中的派生字段添加限制,即,一个不坚持?例如,如果这是我的实体:我可以查询NHibernate中的派生字段吗?
public class Employee
{
public long Id { get; set; }
public string Forename { get; set; }
public string Surname {get; set; }
public string FullName { get { return Forename + " " + Surname; }}
}
,这是映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Domain.Entities"
assembly="Domain">
<class name="Employee" table="`Employee`">
<id name="Id" column="Id" type="long">
<generator class="identity"/>
</id>
<property name="Forename"/>
<property name="Surname"/>
</class>
</hibernate-mapping>
这是我的查询:
public Employee GetByFullName(string fullName)
{
return _session
.CreateCriteria<Employee>
.Add(Restrictions.Eq("FullName", fullName))
.List<Employee>();
}
请忽略的事实,我可以写查询我自己,这是一个微不足道的例子来演示。这在更复杂的情况下会很有用。
你也可以做这样的事情:http://stackoverflow.com/questions/6709463/fuzzy-search-on-a-concatenated-full-name-using-nhibernate –