using "In" restriction for collection in NHibernate
Lets say I have 4 classes
Student { int StudentId, string StudentName, IList<BaseMarks&g开发者_开发技巧t; StudentMarks}
BaseMarks {bool GrandTotalMarks}
SpecializedMarks: BaseMarks {Ilist Results}
Result {string grade, bool Result}
Now, I have a method which populates Students list IList and nested marks collection but typecasts it internally to science marks. I.e. each basemark in Student can be typecasted to ScienceMarks to get practical marks property value.
IList student_List = SomeMethodWhichRetursCollection();
QUESTION How can I filter students who have got "A" grade in any of the subject.
something like:
Students where ((SpecializedMarks)Students.StudentMarks).Result collection. Any of the Grade property's value = "A"
HQL: The Hibernate Query Language
LINQ for NHibernate
// using HQL
var students = Session.CreateQuery("from Students s where s.Grades = :grade")
.SetParameter("grade","A")
.List<Student>();
// using NHibernate.Linq
var students = Session.Linq<Student>().Where(s => s.Grades == "A").ToList();
// or something more complex
var students = Session.Linq<Student>()
.Where(s => s.Grades.Where(x => x.Score == "A"))
.ToList();
精彩评论