对具有NHibernate条件的类调用方法

对具有NHibernate条件的类调用方法,nhibernate,Nhibernate,假设我有一个这样的物体 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

假设我有一个这样的物体

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;}
}
公共班级学生{
公共IList课程作业{get;set;}
公共字符串名称{get;set;}
公共整数{get;set;}
public bool已完成课程作业(int courseyear,string moduleName)
{
返回Courseworks.Any(x=>x.Courseyear==Courseyear&&x.ModuleName==ModuleName&&IsComplete);
}
}
公共课作业{
public int Courseyear{get;set;}
公共字符串ModuleName{get;set;}
公共bool IsComplete{get;set;}
}
当您使用ICriteria查询数据库时,是否可以对学生类调用HasCompletedCoursework方法

干杯
Colin G

否。iCiteria旨在构建Sql查询。如果您可以将此方法更改为某些sql标准,则选择“是”,否则选择-no.

而不是使用标准api,而是使用linq 2 nh api,以
Func
的形式提取一个谓词,该谓词可由
Student
类和存储库(或任何查询者)使用以
Expression
的形式,以便数据库完成工作。

次要重构:IsComplete==true->IsComplete