NHibernate连接子类抛出错误 - 无效列

时间:2016-05-26 03:48:07

标签: c# join nhibernate queryover

我们的模型是:

public class LicensedDevice 
{
    public ISet<HospitalNode> _hospitalNodes;
    public long Id { get; set; }

    public ISet<HospitalNode> HospitalNodes
    {
        get { return _hospitalNodes; }
        set { _hospitalNodes = value; }
    }
}

public class DeviceNode 
{
    public long Id { get; set; }
    public LicensedDevice LicensedDevice { get; set; }
    ... some more properties
}

public class HospitalNode : DeviceNode //Notice the inheritence
{
    ... some properties

    public Hospital Hospital { get; set; }
}

我写了一个QueryOver,我希望LicensedDeviceHospitalNodeHospital。但我得到的SQLException表示在表HospitalNode 中找不到列LicensedDeviceId。这意味着,生成的查询将LicensedDeviceHospitalNode连接,而不是首先将其与DeviceNode连接(因为这是外键存在的位置)。

我尝试了不同的选项来解决此问题 - 例如在readonly中创建DeviceNode LicensedDevice列表并加入它们。但是,如何将DeviceNodeHospitalNode进一步加入?

以下是引发错误的QueryOver

Repository.QueryOver<CareDimension.DomainModel.Models.LicensedDevice>(() => licensedDeviceAlis)
                     .JoinAlias(() => licensedDeviceAlis.HospitalNodes, () => hospitalNodeAlias)
                     .JoinAlias(() => hospitalNodeAlias.Hospital, () => hospitalAlias)
                     .Where(() => hospitalAlias.Id == long.Parse(queryParameters.HospitalId)).List();

我该如何解决这个问题?

0 个答案:

没有答案