对嵌套嵌套属性的Nhibernate Projection

Tec*_*ter 6 nhibernate nhibernate-criteria

我有域类位置

    public abstract class BaseEntity<T> where T: struct 
    {
    public virtual T Id { get; set; }
    public virtual bool Equals(BaseEntity<T> other)
    }

    public class Location : BaseEntity<Int32>
    {

    public  User User {get;set;}
    }

    public class User : BaseEntity<Int32>
    {
    public string Name {get;set;
    }

    public OtherInfo Otherinfo {get;set;};
     }
    public class OtherInfo
    {
    public  string preference {get;set;};
    }

    var criteria = session.CreateCriteria(typeof(Location), "alias");
    criteria.CreateCriteria("User", "user", JoinType.InnerJoin);
    criteria.CreateCriteria("user.Otherinfo", "userInfo",JoinType.InnerJoin); 
    criteria.Add(Restrictions.Eq("user.Id", 100));
    criteria.SetProjection(Projections.Alias(Projections.Id(), "Id"),                            Projections.Alias(Projections.Property("user.Name"), "Name"),  Projections.Alias(Projections.Property("userInfo.preference "), "pref"));
Run Code Online (Sandbox Code Playgroud)

现在,当我执行上述条件时,它会在userInfo.preference上出错.{NHibernate.QueryException:无法解析属性:Otherinfo of:Location.User这里有什么错误.是因为多个嵌套对象

Mar*_*nst 4

使用 CreateAlias 代替:

criteria.CreateAlias("User", "user", JoinType.InnerJoin);
criteria.CreateAlias("user.Otherinfo", "userInfo",JoinType.InnerJoin); 
Run Code Online (Sandbox Code Playgroud)