gpt4 book ai didi

嵌套嵌套属性上的 Nhibernate 投影

转载 作者:行者123 更新时间:2023-12-03 12:43:07 27 4
gpt4 key购买 nike

我有域类位置

    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"));

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

最佳答案

改用 CreateAlias:

criteria.CreateAlias("User", "user", JoinType.InnerJoin);
criteria.CreateAlias("user.Otherinfo", "userInfo",JoinType.InnerJoin);

关于嵌套嵌套属性上的 Nhibernate 投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10738456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com