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()
开发者_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!
精彩评论