I have this piece of code in a TaskRepository :
public List<Task> GetActiveTasks()
{
return SessionContainer.Session
.Query<Task>()
.Where(t => t.IsActive())
.ToList();
}
And this is the IsActive() method in the Task Class
public virtual bool IsActive()
{
return States.ToList().Max().Name == "Active";
}
My problem is that GetActiveTasks() returns NotSupportedException.
Does anyone knows whats the problem ? I think it is not possible to call instance methods in the Where predicate. If that is not possible, is there any workaround for this? I need to get all the active tasks but I dont know how to do it if it is not like this.
The lambdas given in the Query have to be translated to sql. How should NHibernate interprete a method implemented by you? it can’t. However you could map IsActive as a Formula property and query that. Something like: