我無法指定QueryOver order by子句的屬性名稱與列名稱不匹配的對象。通過別名與NHibernate的QueryOver使用屬性名稱而不是列映射
這裏是對象: -
public class ObjectInstance
{
public ObjectInstance()
{
IsActive = true;
}
public virtual bool IsActive { get; set; }
}
而且休眠流利的映射: -
public class ObjectInstanceMap : ClassMap<ObjectInstance>
{
public ObjectInstanceMap()
{
Table("ObjectInstances");
Id(obj => obj.ObjectInstanceId).GeneratedBy.GuidComb();
Map(x => x.IsActive, "ObjectInstanceIsActive");
}
}
正如你可以看到在數據庫稱爲ObjectInstanceIsActive列,但被映射到ObjectInstance對象上的IsActive屬性。試圖讓一個IList出了QueryOver如下: -
IList<ObjectInstance> result = this.Session.QueryOver<ObjectInstance>(() => objectInstance)
.UnderlyingCriteria.AddOrder(new Order("ObjectInstanceIsActive", true))
.List<ObjectInstance>();
拋出一個錯誤,指出ObjectInstance對象不具有ObjectInstanceIsActive屬性,這是正確的,事實並非如此。
如果我改變的標準是: -
IList<ObjectInstance> result = this.Session.QueryOver<ObjectInstance>(() => objectInstance)
.UnderlyingCriteria.AddOrder(new Order("IsActive", true))
.List<ObjectInstance>();
則Hibernate成功生成SQL查詢,但其尋找一個叫IsActive列其中不存在和錯誤。
我也嘗試添加下面的預測(單獨),但沒有幫助。
.Select(Projections.ProjectionList().Add(Projections.Property("IsActive"), "ObjectInstanceIsActive"))
.Select(Projections.ProjectionList().Add(Projections.Property("IsActive"), "ObjectInstanceIsActive"))