无法在nhibernate中找到命名参数[InboundResultsId]

时间:2013-03-07 17:25:04

标签: nhibernate

我正在使用nHibernate并尝试执行以下代码:

string hql = "select a from Applicant a with (nolock) where a.Inbound_Results_Id = :InboundResultsId";


    try
    {
        IList<Applicant> applicants = _ws.Session.CreateQuery(hql)
                    .SetParameter("InboundResultsId", indata.Inbound_Results_Id)
                    .List<Applicant>();
    }
    catch (NullReferenceException)
    {
        Logger.LogMsg("No applicant data was found when looking for unmatched applicants.");
    }

我收到以下例外:

无法找到命名参数[InboundResultsId]

我为什么会收到此错误?

谢谢! 跳蚤

1 个答案:

答案 0 :(得分:0)

愚蠢的错误。事实证明 Inbound_Results_Id 不是我的Applicant类的属性。我的申请人类具有名为 InboundResult 的复杂对象的属性,而该对象又具有名为 Inbound_Results_Id 的属性。所以我需要做的就是为我的HQL做这个:

   string hql = "select a from Applicant a where a.Inbound_Result.Inbound_Results_Id = :inboundResult and a.Harvest_Result_Processed = 0 and a.Applicant_Id not in (" + applicantIdList + ") and a.Status in ('Generated','Received')";

以下是完整的代码:

string hql = "select a from Applicant a where a.Inbound_Result.Inbound_Results_Id = :inboundResult and a.Harvest_Result_Processed = 0 and a.Applicant_Id not in (" + applicantIdList + ") and a.Status in ('Generated','Received')";

IList<Applicant> unmatchedApplicants = new List<Applicant>();

try
{
    unmatchedApplicants = _ws.Session.CreateQuery(hql)
        .SetParameter("inboundResult", indata.Inbound_Results_Id.ToString())
        .List<Applicant>();
}
catch (NullReferenceException)
{
    Logger.LogMsg("No applicant data was found when looking for unmatched applicants.");
}

这是我的申请人类:

    public class Applicant : Person
    {

        public virtual long? Applicant_Id { get; protected set; }
        public virtual string Status { get; set; }
        public virtual Account App_Account { get; set; }
        public virtual string Carrier_Name { get; set; }

        public virtual InboundResult Inbound_Result { get; set; }

        //Applicant Demographics
        public virtual string Middle_Name { get; set; }
        public virtual string Gender { get; set; }
        public virtual DateTime? DOB { get; set; }

}

这是我的InboundResult类:

public class InboundResult
{

    public virtual long? Inbound_Results_Id { get; protected set; }
    public virtual string File_Name { get; set; }
    public virtual string Status { get; set; }
    public virtual string Header_Line { get; set; }
    public virtual string Contents { get; set; }
    public virtual string Support_Notes { get; set; }
    public virtual DateTime Create_DateTime { get; set; }
    public virtual DateTime Update_DateTime { get; set; }
    public virtual string User_Name { get; set; }
}