Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按Id查找的NHibernate标准_Nhibernate_Criteria - Fatal编程技术网

按Id查找的NHibernate标准

按Id查找的NHibernate标准,nhibernate,criteria,Nhibernate,Criteria,我有两个实体: public class Authority : Entity { [NotNull, NotEmpty] public virtual string Name { get; set; } [NotNull] public virtual AuthorityType Type { get; set; } } public class AuthorityType : Entity { [NotNull, NotEmpty] pu

我有两个实体:

public class Authority : Entity
{
    [NotNull, NotEmpty]
    public virtual string Name { get; set; }

    [NotNull]
    public virtual AuthorityType Type { get; set; }

}

public class AuthorityType : Entity
{
    [NotNull, NotEmpty]
    public virtual string Name { get; set; }

    public virtual string Description { get; set; }
}
现在我希望按类型查找存储库中的所有权限。我试着这样做:

    public IList<Authority> GetAuthoritiesByType(int id)
    {
        ICriteria criteria = Session.CreateCriteria(typeof (Authority));
        criteria.Add(Restrictions.Eq("Type.Id", id));
        IList<Authority> authorities = criteria.List<Authority>();
        return authorities;            
    }
public IList GetAuthoritiesByType(int-id)
{
ICriteria criteria=Session.CreateCriteria(typeof(Authority));
添加(Restrictions.Eq(“Type.Id”,Id));
IList authorities=criteria.List();
返回当局;
}
但是,我收到一个错误,表明SQL有问题(“无法执行查询”。innerexception如下:{“无效列名'TypeFk'。\r\n无效列名'TypeFk'。”

有什么建议吗?还有其他方法吗

致以最良好的祝愿,
Andrew

看起来您的权限实体映射文件正在将
Type
属性与权限实体映射到的任何表中名为
TypeFk
的列相关联。由于某种原因,该列不存在


查看您的映射文件可能也会有所帮助。

谢谢您指出了正确的方向。我使用的是Fluent,并且我错误地映射了ForeignKeyConvention。很高兴听到这一点。也许您可以帮助一个brutha,投票并回答mark?您知道,这给女性留下了深刻的印象……我需要所有可以得到的帮助。:PHaha-这里有一点可以帮助您ore和这里所有的狐狸精女孩在一起,都是为了一个男人的大名声