是否可以向實體中的派生字段添加限制,即,一個不堅持?例如,如果這是我的實體:我可以查詢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 –