Is it possible to add a restriction to a derived field in an entity, ie. one that is not persisted? For example, if this is my entity:
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; }}
}
and this is the mapping:
<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>
And this is my query:
public Employee GetByFullName(string fullName)
{
return _session
.CreateCriteria<Employee>
.Add(Restrictions.Eq("FullName", fullName))
.List<Employee>();
}
Please ignore the fact that I could write the query myself, this is a trivial example to demonstrate. This would be useful in far more complex scenarios.