开发者

Nhibernate criteria error

开发者 https://www.devze.com 2023-04-04 00:17 出处:网络
this code public IList<Patient> GetByMRNNameDOB(Patient patient) { using (ISession session = SessionManager.Current.OpenSession())

this code

        public IList<Patient> GetByMRNNameDOB(Patient patient)
    {
        using (ISession session = SessionManager.Current.OpenSession())
        {
            ICriteria criteria = session.CreateCriteria(typeof (Patient))
                .Add(Expression.Disjunction()
                         .Add(Expression.Eq("patient.MedicalRecordNumber", patient.MedicalRecordNumber))
                         .Add(Expression.Conjunction()
            开发者_JAVA技巧                      .Add(Expression.Eq("patient.FirstName", patient.FirstName))
                                  .Add(Expression.Eq("patient.LastName", patient.LastName))
                                  .Add(Expression.Eq("patient.Birthday", patient.Birthday))));

            return criteria.List<Patient>();
        }
    }

throws an error:

Could not resolve property: patient of: SolutionConsultants.WebScreening.Entities.Patients.Patient

Type for which Type.IsGenericParameter is true

any ideas?


ICriteria criteria = session.CreateCriteria(typeof (Patient))
    .Add(Expression.Disjunction()
                     .Add(Expression.Eq("MedicalRecordNumber", 
                                        patient.MedicalRecordNumber))
                     .Add(Expression.Conjunction()
                              .Add(Expression.Eq("FirstName", patient.FirstName))
                              .Add(Expression.Eq("LastName", patient.LastName))
                              .Add(Expression.Eq("Birthday", patient.Birthday))))


I don't know if this is what you had in mind, but probably patient is just an alias that you wanted to use for the query, if that's the case you can simply include it in the CreateCriteria method like so (not tested, I'm away from my computer):

ICriteria criteria = session.CreateCriteria(typeof(Patient), "patient");
...

Hope it helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消