English 中文(简体)
NHibernate: 有可能根据别名增加限制
原标题:NHibernate: Is it possible to add restriction based on alias name

Say I建立了标准查询,并与Alisas ToBean的异构体转化。

session.CreateCriteria<Staff>("s")
  .CreateAlias("supervisor", "super")
  .SetProjection(Projections.ProjectionList()
    .Add(Projections.Property("s.name"), "name")
    .Add(Projections.Property("super.name"), "supervisor_name"))
  .SetResultTransformer(Transformers.AliasToBean<StaffView>());

如果你只知道死者的财产名称,是否有可能增加限制? 您可以使用美籍财产名称添加Order,但限制似乎只符合实际财产名称。 我猜想这一点,是因为在转变之前适用这些内容,与你一样,在条款中不使用一栏,但你可以按顺序排列。

//throws exception like cannot find property supervisor_name in Staff class
//only "super.name" works
.Add(Restrictions.Like("supervisor_name", "blah"))

//this works though
.AddOrder(Order.Asc("supervisor_name")) 

因此,基本上,我需要一种办法,根据具体情况获得被遗忘的财产名称。 我可以考虑采取多种方法这样做,但我希望恩赫特有某种现有方法? 例如,我可以单独保存一份财产图,以具体列出姓名,或仅绘制数据库图,这样就不必改变为人。

问题回答

It should work with name of alias dot property name. {alias}.Name.

或者我是否误解了你的问题?





相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签