I implemented a specification template with Linq as described here https://www.packtpub.com/article/nhibernate-3-using-linq-specifications-data-access-layer
Now I want to add the ability to download and do not know how best to do it.
Generic repository class in a related example:
public IEnumerable<T> FindAll(Specification<T> specification)
{
var query = GetQuery(specification);
return Transact(() => query.ToList());
}
public T FindOne(Specification<T> specification)
{
var query = GetQuery(specification);
return Transact(() => query.SingleOrDefault());
}
private IQueryable<T> GetQuery(
Specification<T> specification)
{
return session.Query<T>()
.Where(specification.IsSatisfiedBy());
}
And the specification implementation:
public class MoviesDirectedBy : Specification<Movie>
{
private readonly string _director;
public MoviesDirectedBy(string director)
{
_director = director;
}
public override
Expression<Func<Movie, bool>> IsSatisfiedBy()
{
return m => m.Director == _director;
}
}
This works well, now I want to add the ability to be able to download. I understand that loading NHibernate can be done using Fetch in the request.
I am looking for whether to encapsulate the logic of a loadable load into a specification or pass it to a repository, as well as the syntax of the Linq / expression tree needed to achieve this (for example, an example of how this will be done).