tags:

views:

17

answers:

1

Lets say I have 4 classes

Student { int StudentId, string StudentName, IList<BaseMarks> 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"

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();
Rafael Belliard
thanks for the reply... but the problem is that student contains a base class property "BaseMarks" which does not have "Grades" hence s=>s. will only give GrandTotalMarks. I need to typecast marks to specializedmarks.
enableDeepak