开发者

using "In" restriction for collection in NHibernate

开发者 https://www.devze.com 2023-01-11 20:51 出处:网络
Letssay I have 4 classes Student { int StudentId, string StudentName, IList<BaseMarks&g开发者_开发技巧t; StudentMarks}

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();
0

精彩评论

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