tags:

views:

37

answers:

2

Say i have a object like this

public class Student{
    public IList<Coursework> Courseworks{get;set;}
    public string Name{get;set;}
    public int Age{get;set;}

    public bool HasCompletedCoursework(int courseyear, string moduleName)
    {
         return Courseworks.Any(x => x.Courseyear == courseyear && x.ModuleName == moduleName && IsComplete);
    }
}

public class Coursework{
    public int Courseyear{get;set;}
    public string ModuleName{get;set;}
    public bool IsComplete {get; set;}
}

is it possible to call the HasCompletedCoursework method on the Student class when you use ICriteria to query the database.

Cheers Colin G

A: 

No. ICriteria is designed to build Sql queries. If you can change this method to some sql criteria, then yes, otherwise - no.

Sly
+1  A: 

Instead of using the criteria api, but instead using the linq 2 nh api, extracting a predicate in the form of Func<bool, Student> that could be used both by the Student class and the repository (or whoever queries) in the form Expression<Func<bool, Student>> in order for the DB to do the work.

Martin R-L