a1exis
a1exis

Reputation: 39

Nhibernate criteria error

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()
                                  .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?

Upvotes: 0

Views: 118

Answers (2)

Diego Mijelshon
Diego Mijelshon

Reputation: 52745

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

Upvotes: 2

MonkeyCoder
MonkeyCoder

Reputation: 2620

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!

Upvotes: 0

Related Questions